问题:最近一个项目,当已选的项总数超过设定的值时弹出提示框。
通过事件的监听的形式。<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />比如当超过3个时弹出提示框。
通过事件的监听的形式。<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />比如当超过3个时弹出提示框。
<div id="con">
<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />
</div>
<script>
$('#con input:checkbox').click(function(){
if($('#con input:checked').length>3){
alert('')
};
});
</script>
<div>设置选择上限:<input type="text" id="num" />个</div>
<div id="con">
<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />
<input type="checkbox" name="[]" />
</div>
<script>
var a=0;
a=document.getElementById("num").value;
$('#con input:checkbox').click(function(){
if($('#con input:checked').length>a){
alert('最多只能选择'+a+'个');
};
});
</script>