<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<form action="" id="form1">
<input type="checkbox" name="checks"/>1111
<input type="checkbox" name="checks"/>2222
<input type="checkbox" name="checks"/>3333
<input type="checkbox" name="checks"/>4444
<input type="checkbox" name="checks"/>5555
</form>
<script>
var oF = document.getElementById("form1");
for(var i=0;i<oF.checks.length;i++){
oF.checks[i].onclick = function (){
var m = 0;
for(var j=0;j<oF.checks.length;j++){
if(oF.checks[j].checked){
m++;
}
}
if(m>3){
return false;
}
}
}
</script>
</body>
</html>
练习-带有数量限制的多选
最新推荐文章于 2020-08-03 23:46:05 发布