var Len =document.forms[0].elements.length;//取得表单里所有控件个数 for(var i =0;i<Len;i++){ var obj =document.forms[0].elements[i]; if(obj.type="checkbox"&&obj.checked=="true"){//如果控件类型为复选,且被选中 提示 alert("你选中了checkbox"); } }
checkbox: 看checked属性是否为true
例子 这里有http://gubo85.bokee.com/viewdiary.16088621.html如判断下面的是否被checked <input name="id_type" type="radio" value="cid1"> <input name="id_type" type="radio" value="cid2"> <input name="id_type" type="radio" value="cid3"> <input name="id_type" type="radio" value="cid4">for (var i = 0; i < document.getElementsByName("id_type").length; i ++) { if (document.getElementsByName("id_type")[i].checked == true) { alert(document.getElementsByName("id_type")[i].value); } }
var Len =document.forms[0].elements.length;//取得表单里所有控件个数
for(var i =0;i<Len;i++){
var obj =document.forms[0].elements[i];
if(obj.type="checkbox"&&obj.checked=="true"){//如果控件类型为复选,且被选中 提示
alert("你选中了checkbox");
}
}
<input name="id_type" type="radio" value="cid1">
<input name="id_type" type="radio" value="cid2">
<input name="id_type" type="radio" value="cid3">
<input name="id_type" type="radio" value="cid4">for (var i = 0; i < document.getElementsByName("id_type").length; i ++)
{
if (document.getElementsByName("id_type")[i].checked == true)
{
alert(document.getElementsByName("id_type")[i].value);
}
}
谁在说说呗~单选多选 用ducoment.表单.单选[X].checked=true来判断下拉菜单 呵呵 还是没明白 哪为 在说下吧~~~
<select name="aa" style="width:60%" onChange="javascript:showoption();">
<option value="1">語文</option>
<option value="1">數學</option>
<option value="1">英語</option>
<option value="1">歷史</option>
</select>function showoption()
{var n=document.all("aa").selectedIndex;
alert(n);
var ss= document.all("aa").options[n].text;
alert(ss);
}
<title></title>
<script language="javascript">
function show(){
var obj =document.myform.sel;
switch(obj.options[obj.selectedIndex].text){
case "haha":
alert("haha");
break;
case "xixi":
alert("xixi");
break;
case "hehe":
alert("hehe");
break;
default:
alert("shu ru");
}
}
</script>
</head>
<form name="myform">
<body>
<select name= "sel" id="sel" style= "width:20%" onChange="show()">
<option value= "1"> </option>
<option value= "haha"> haha </option>
<option value= "xixi"> xixi </option>
<option value= "huhu"> huhu </option>
</select>
</body>
</form>
</html>
optinos 以前少了 S谢谢~~实验成功 马上回来给分~~~