87,990
社区成员
发帖
与我相关
我的任务
分享
<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>
<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>