<input type="checkbox" name="fruit" value="apple" />苹果
<input type="checkbox" name="fruit" value="orange" />橘子
<input type="checkbox" name="fruit" value="banana" />香蕉
<input type="checkbox" name="fruit" value="grape" />葡萄
<button id="bt1">判断选中</button>
<script>
$(function (){
$("#bt1").click(function (){
var checkVal='';//查找已选的值
$("input[name='fruit']:checkbox").each(function(){
if($(this).prop('checked')){
checkVal+=$(this).val()+',';
}
})
console.log(checkVal);
var flag=false;//判断是否选中值
$("input[name='fruit']:checkbox").each(function(){
if($(this).prop('checked')){
flag=true;
}
})
console.log(flag)
if(flag){
alert('有被选中');
}else{
alert('没有选中任何选项');
}
})
})
</script>
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!