This article mainly introduces the jquery method to determine whether a check box is selected. Friends in need can refer to it.
Jquery summarizes the problem of determining whether a check box is selected and how to select it.
Let’s get to the point, or when the page has the following set of check boxes:
<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">葡萄
Then use Jquery to get a set of name=fruit The method of checking the value of the check box is as follows:
var checkVal=''; $("input[name='fruit']:checkbox").each(function(){ if($(this).attr('checked')){ checkVal+=$(this).val()+','; } }) 判断 name=fruit 组的复选框是否有被选中的选项: var flag=false; $("input[name='fruit']:checkbox").each(function(){ if($(this).attr('checked')){ flag=true; } }) if(flag){ alert('有被选中'); }else{ alert('没有选中任何选项'); }
The above is the method of jquery to determine whether the check box is selected. I hope it will be helpful to everyone's study. That’s all the content of this chapter. For more related tutorials, please visit jQuery Video Tutorial!