获取checkbox的值,实例如下:
<html>
<form name=\"orderForm\">
<input type=\"checkbox\" name=\"onion\" value=\"hot onion\">Onion<br>
<input type=\"checkbox\" name=\"bacon\" value=\"spicy bacon\">Bacon<hr>
<input type=\"button\" value=\"Order Pizza\" name=\"orderButton\" =\"console.log(\'ordered.\')\">
</form>
< language=\" \">
document.write(document.orderForm.onion.value);
document.write(\" or \",document.orderForm.bacon.value);
</ >
</html>
再来看一个实例,该实例获取所有被选中的checkbox值:
<html>
<head>
< http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
< >js</ >
</head>
< language=\" \">
function aa(){
var r=document.getElementsByName(\"r\");
for(var i=0;i<r.length;i++){
if(r[i].checked){
alert(r[i].value+\",\"+r[i].nextSibling.nodeValue);
}
}
}
</ >
<body>
<form name=\"form1\" method=\"post\" action=\"\">
<input type=\"checkbox\" name=\"r\" value=\"1\">a<br>
<input type=\"checkbox\" name=\"r\" value=\"2\">b<br>
<input type=\"checkbox\" name=\"r\" value=\"3\">c<br>
<input type=\"checkbox\" name=\"r\" value=\"4\">d<br>
<input type=\"checkbox\" name=\"r\" value=\"5\">e<br>
<input type=\"checkbox\" name=\"r\" value=\"6\">f<br>
<input type=\"checkbox\" name=\"r\" value=\"7\">g<br>
<input type=\"checkbox\" name=\"r\" value=\"8\">h<br>
<input type=\"checkbox\" name=\"r\" value=\"9\">i<br>
<input type=\"checkbox\" name=\"r\" value=\"10\">j<br>
<br>
<input type=\"button\" =\"aa()\" value=\"button\">
</form>
</body>
</html> 继续阅读与本文标签相同的文章
-
今晚上市,上等设计团队,全球首搭L3自动驾驶,零百加速3秒9
2026-05-15栏目: 教程
-
原来Word竟可以折叠?
2026-05-15栏目: 教程
-
实物资产管理软件操作手册
2026-05-15栏目: 教程
-
欧司朗研发新款LED智能车头灯,超2.5万可控独立像素让汽车更智能
2026-05-15栏目: 教程
-
Surprise 你天天登录的OA系统,全新升级啦
2026-05-15栏目: 教程
