<html>
<head>
<title>判断input输入框的个数</title>
</head>
<body>
<script language="javascript">
function checkInputBox(object){
var f_str = '';
var count = 0;
$("input[name='goods_id']").each(function(){
if($(this).attr("checked")){
count++;
f_str += ","+$(this).val();
}
})
f_str = f_str.slice(1);
if(count >2){
alert("温馨提示:只能选择2-4个");
$(object).attr("checked",false)
}
}
</SCRIPT>
<div>
<input type="checkbox" name="goods_id" οnclick="checkInputBox(this)"/>1
<input type="checkbox" name="goods_id" οnclick="checkInputBox(this)"/>2
<input type="checkbox" name="goods_id" οnclick="checkInputBox(this)"/>3
<input type="checkbox" name="goods_id" οnclick="checkInputBox(this)"/>4
<input type="checkbox" name="goods_id" οnclick="checkInputBox(this)"/>5
<input type="checkbox" name="goods_id" οnclick="checkInputBox(this)"/>6
</div>
</body>
</html>
js判断复选框的数量
最新推荐文章于 2020-02-01 15:42:38 发布