How to check multiple checkboxes checked using jquery?

前端 未结 5 1734
别那么骄傲
别那么骄傲 2021-01-19 02:27

i am new to the jquery, it is quite interesting, but i am having a little problem, i am populating multiple checkboxes from database using foreach loop like this,



        
5条回答
  •  别那么骄傲
    2021-01-19 03:26

    First of all id of the checkboxes should be unique.

    Do like this

    
        
    
    

    Now in jQuery check like this to get all the checkboxes thats checked.

    var checkCount = $("input[name='city[]']:checked").length;
    
    if(checkCount == 0)
    {
       alert("Atleast one checkbox should be checked.");
    }
    

提交回复
热议问题