帮忙看看这个js错在哪里?
我是想要radio选中N的时候才提示的,现在情况是我没选中或选中Y都提示了,,错在哪里呀?
- VBScript code
<script>function beforesubmit(){ if (document.getElementById("FixYN").value="N")//if (document.form1.FixYN.value ="N" ){ if (document.form1.BBPre.value!="") { var len1 = document.form1.BBPre.value.length //获取判定值的度 var BBPre1 = document.form1.BBPre.value var beginno1 = document.form1.beginno.value //取beginno的值 var beginno2 = (beginno1.substr(0,len1)) if (BBPre1 != beginno2) {alert("首判定不!")form1.beginno.focus();return false;}}}}</script><form id="form1" name="form1" method="post" action="" onsubmit="return beforesubmit()"> <p> <label for="BBPre"></label> <input name="BBPre" type="text" id="BBPre" value="ABCD" /> Y : <input type="radio" name="FixYN" id="FixYN" value="Y" /> N: <label for="FixYN"></label> <input type="radio" name="FixYN" id="FixYN" value="N" /> <label for="FixYN"></label> </p> <p> <label for="beginno"></label> <input type="text" name="beginno" id="beginno" /> </p> <p> <input type="submit" name="button" id="button" value="提交" /> </p></form>[解决办法]
radio的控件判定选不选中不是checked属性么?
[解决办法]
用checked属性
[解决办法]
不同的input id属性要唯一,
通常这种情况下,是通过getElementsByName()来取DOM数组,再用checked来判断当前radio的value值。
你这个要想方便的话,两个ID设成不同的,直接判断N的checked属性
[解决办法]
- HTML code
<script>function beforesubmit(){ if (document.getElementById("FixY").checked)//if (document.form1.FixYN.value ="N" ){ if (document.form1.BBPre.value!="") { var len1 = document.form1.BBPre.value.length //获取判定值的度 var BBPre1 = document.form1.BBPre.value var beginno1 = document.form1.beginno.value //取beginno的值 var beginno2 = (beginno1.substr(0,len1)) if (BBPre1 != beginno2) {alert("首判定不!")form1.beginno.focus();return false;}}}}</script><form id="form1" name="form1" method="post" action="" onsubmit="return beforesubmit()"> <p> <label for="BBPre"></label> <input name="BBPre" type="text" id="BBPre" value="ABCD" /> Y : <input type="radio" name="FixYN" id="FixY" value="Y" /> N: <label for="FixYN"></label> <input type="radio" name="FixYN" id="FixN" value="N" /> <label for="FixYN"></label> </p> <p> <label for="beginno"></label> <input type="text" name="beginno" id="beginno" /> </p> <p> <input type="submit" name="button" id="button" value="提交" /> </p></form>