<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>判断复选框至少选一项</title>
</head>
<body>
<input type="checkbox" name="checkselect">
<input type="checkbox" name="checkselect">
<input type="checkbox" name="checkselect">
<input type="checkbox" name="checkselect">
<input type="submit" value="提交" id="submitbtn">
<script>
window.οnlοad=function(){
var checkboxs=document.getElementsByName("checkselect"),submitbtn=document.getElementById("submitbtn");
submitbtn.οnclick=function(){
for(var i in checkboxs){ //枚举出checkboxs的属性
if(checkboxs[i].checked){
console.log("至少选中一项了");
return;
}
}
alert("未选中任何项!");
}
}
</script>
</body>
</html>
javascript判断复选框至少选中一项
最新推荐文章于 2023-04-12 17:02:12 发布