获取checkbox复选框的值
程序员文章站
2022-04-05 15:16:52
...
<title>CheckBox</title>
<script type = "text/javascript">
doGetVal: function doGetVal()
{
//var fruitName = document.getElementById("apple").value;//根据ID获取值
//alert(fruitName);
//
var fruit = document.getElementsByName("fruit"); //根据Name拿到集合数组
for (var i=0;i<fruit.length;i++ )
{
if (fruit[i].checked)//checkbox是否选中
{
var fruitName = fruit[i].value;
alert(fruitName);
}
}
}
</script>
</head>
<body>
<div align="left">
<input type = "checkBox" id="apple" name="fruit" value="apple"/>apple<br>
<input type = "checkBox" name="fruit" value="watermelon"/>watermelon<br>
<input type = "checkBox" name="fruit" value="strawberry"/>strawberry<br>
<input type = "button" onclick="doGetVal()" value = "click"/>
</div>
</body>
</html>
上一篇: WebKit in Android Framework
下一篇: 二级基础知识