<html>
<head>
<script>
function test(testform){
for(var i = 0; i < testform.checktest.length; i++){
if(testform.checktest[i].checked)
break;
}
alert(testform.checktest[i].value);
}
</script>
</head>
<body>
<form name="radiotest">
<input type="radio" name="checktest" value="aa"/>
<input type="radio" name="checktest" value="bb"/>
<input type="radio" name="checktest" value="cc"/>
<input type="radio" name="checktest" value="dd"/>
<input type="button" name="testbutton" value="test" onClick="test(this.form)"/>
</form>
</body>
</html>很简单一个程序,但我想不通的是,js函数中定义的变量i应该是在for循环里,怎么出了for循环还能用呢?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货