Can I use jQuery to check whether at least one checkbox is checked?

前端 未结 6 1604
礼貌的吻别
礼貌的吻别 2020-12-01 02:08

I have the following HTML form which can have many checkboxes. When the submit button is clicked, I want the user to get a javascript alert to check at least one checkbox if

6条回答
  •  抹茶落季
    2020-12-01 02:25

    $("#show").click(function() {
        var count_checked = $("[name='chk[]']:checked").length; // count the checked rows
            if(count_checked == 0) 
            {
                alert("Please select any record to delete.");
                return false;
            }
            if(count_checked == 1) {
                alert("Record Selected:"+count_checked);
    
            } else {
                alert("Record Selected:"+count_checked);
              }
    });
    

提交回复
热议问题