admin 发表于 2014-2-17 21:29:32

JS判断radio单选按钮是否选中

<!doctype html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<title>JS判断radio单选按钮是否选中</title>
<script type="text/javascript">
function ValidateRadio(){
var radioSelete = "Nothing";
var seletedValue;
for(i=0;i<document.form1.rValue.length;i++){
if(document.form1.rValue.checked)   {
radioSelete = "seleted";
seletedValue = document.form1.rValue.value;
}
}
if(radioSelete == "Nothing"){
alert("请选择一个地名");
return false;
}else{
alert("您选中的是:"+seletedValue);
return true;
}
}
</script>
</head>
<body>
<form name="form1">
<input type="radio" name="rValue" value="四川">四川
<input type="radio" name="rValue" value="江苏">江苏
<input type="radio" name="rValue" value="南京">南京
<input type="radio" name="rValue" value="天津">天津
<input type="radio" name="rValue" value="上海">上海
<input type="button" onclick="return ValidateRadio()" value="验证">
</form>
</body>
</html>

页: [1]
查看完整版本: JS判断radio单选按钮是否选中