Javascript实例:用js判断单选按纽是否选中,代码如下 <html xmlns=”http://www.w3.org/1999/xhtml”> <script> var flag = false; var radios=document.getElementsByName(“dwww”); 您最喜欢设计家园的哪个频道内容?<br> <input type=”radio” name=”dwww” value=”1″>酷站欣赏 http://www.dwww.cn/cool.asp <br> <input type=”submit” name=”Submit” value=”提交”/>
\n
\n
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″ />
<title>设计家园投票 http://www.dwww.cn</title>
</head>
<body>
\n
function chkform(){
\n
\n
for(var i=0;i<radios.length;i++)
{
if(radios[i].checked==true)
{
flag = true;
break;
\n
}
}
if(!flag)
{
alert(“请至少选择一项!”)
return false
};
\n
}
</script>
<form name=”form” method=”post” action=”http://www.dwww.cn” onSubmit=”return chkform()”>
\n
\n
<input type=”radio” name=”dwww” value=”2″>网页教程 http://www.dwww.cn/design.asp <br>
<input type=”radio” name=”dwww” value=”3″>网页素材 http://www.dwww.cn/photo.asp <br>
\n
</form>
\n
</body>
</html>
作者:无情 转载请注明来源:http://www.dwww.cn