<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>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号