document.form1.age[0].selected == true
解决方案 »
- 求助:关于js局部刷新父页面的某个控件
- move an image within a DIV --- 拖动(drag)image向下移动?
- 100分求jQuery Datepicker的使用
- ASP批量删除复选框选中后为什么不能取消选择
- 如何做出点击图片,图片居中,其他部分阴影显示
- 详细画面每次只能弹出一个子画面,如何去实现???????
- 在層裡面怎麼控制圖片的顯示比例啊
- 哪个哥哥帮下,分不够,再加啊! 之 二
- 小弟刚来到这里。想问一下,大家都用什么编辑器写javascript?什么编辑器比较好呀?
- 急求解答:javascript的一个Cookie问题。
- TextBox显示日期和时间!!
- 表格上修改数据或删除
for (i = 0;i<=form1.age.length;i++) {
if(form1.age[i].checked) {
alert(form1.age[i].value)
}
}
}
</script>
<h1 align="center">第三题</h1>
<form name="form1" method="post" onsubmit="return validate();">
请选择年龄:
<input type="radio" name="age" value="对不起,您未满18岁,没有权利投票!" checked="checked" />年龄小于18岁
<input type="radio" name="age" value="请慎重投下您宝贵的一票!" />年龄大于等于18岁
<br />
<input type="reset" value="重填" />
<input type="submit" value="提交" />
</form>
我采用另外的一种方式将这个功能给实现了...
但是我发现我上面的这段代码只在IE浏览器中有作用,在firefox中就没作用了!!这又是怎么回事呢?
请各位高人指点!!
if (document.form1.age[0].value = true) { //应该是if (document.form1.age[0].value == "option1")
document.form1.age[0].value 原来值是"option1",将true赋值给document.form1.age[0],document.form1.age[0].value的值为true。而在执行document.form1.age[0].value = true这条语句的时候,返回的结果始终是true,所以不管怎么运行,都会进入第一个if,而不执行else if后面的条件判断。
function validate () {
if (document.form1.age[0].value == "option1") {
alert("对不起,您未满18岁,没有权利投票!");
//return true;
}
else if(document.form1.age[1].value == "option2") {
alert("请慎重投下您宝贵的一票!");
//return true;
}
//return true;
}
</script > <h1 align="center" >第三题 </h1 >
<form name="form1" method="post" onsubmit="validate();" >
请选择年龄:
<input type="radio" name="age" value="option1" / >年龄小于18岁
<input type="radio" name="age" value="option2" / >年龄大于等于18岁
<br / >
<input type="reset" value="重填" / >
<input type="submit" value="提交" / > 如你所说修改,但还是不行哦...
function validate () {
alert(document.form1.age[0].value);
alert(document.form1.age[1].value);
if (document.form1.age[0].checked) {
alert("对不起,您未满18岁,没有权利投票!");
return true;
}
else if(document.form1.age[1].checked) {
alert("请慎重投下您宝贵的一票!");
return true;
}
return true;
}
function validate () {
if (document.form1.age[0].checked) {
alert("对不起,您未满18岁,没有权利投票!");
return true;
}
else if(document.form1.age[1].checked) {
alert("请慎重投下您宝贵的一票!");
return true;
}
return true;
}
</script > <form name="form1" method="post" onsubmit="validate();" >
请选择年龄:
<input type="radio" name="age" value="option1" / >年龄小于18岁
<input type="radio" name="age" value="option2" / >年龄大于等于18岁
<br / >
<input type="reset" value="重填" / >
<input type="submit" value="提交" / > 呵呵,谢谢了啊...终于搞掂这个问题咯....
if (document.form1.age[0].checked == true) {
alert("对不起,您未满18岁,没有权利投票!");
return true;
}
else if(document.form1.age[1].checked== true) {
alert("请慎重投下您宝贵的一票!");
return true;
}
return true;
}
</script > </head><body>
<h1 align="center" >第三题 </h1 >
<form name="form1" method="post" onsubmit="return validate();" >
请选择年龄:
<input type="radio" name="age" value="option1" / >年龄小于18岁
<input type="radio" name="age" value="option2" / >年龄大于等于18岁
<br / >
<input type="reset" value="重填" / >
<input type="submit" value="提交" / >
</form > </body>
</html>