how to get multiple checkbox value using jquery

前端 未结 12 704
终归单人心
终归单人心 2020-11-29 20:11

How can I get the value of checkboxes which are selected using jquery? My html code is as follows:



        
相关标签:
12条回答
  • 2020-11-29 20:11

    Try getPrameterValues() for getting values from multiple checkboxes.

    0 讨论(0)
  • 2020-11-29 20:15

    You may try;

    $('#save_value').click(function(){
        var final = '';
        $('.ads_Checkbox:checked').each(function(){        
            var values = $(this).val();
            final += values;
        });
        alert(final);
    });
    

    This will return all checkbox values in a single instance.

    Here is a working Live Demo.

    0 讨论(0)
  • 2020-11-29 20:17

    To get an array of values from multiple checked checkboxes, use jQuery map/get functions:

    $('input[type=checkbox]:checked').map(function(_, el) {
        return $(el).val();
    }).get();
    

    This will return array with checked values, like this one: ['1', '2']

    Here is working example on jsfiddle: http://jsfiddle.net/7PV2e/

    0 讨论(0)
  • 2020-11-29 20:21

    try this one.. (guys I am a new bee.. so if I wrong then I am really sorry. But I found a solution by this way.)

    var suggestion = [];
    $('#health_condition_name:checked').each(function (j, ob) {
    
        var odata = {
            health_condition_name: $(ob).val()
        };
    
        health.push(odata);
    });
    
    0 讨论(0)
  • 2020-11-29 20:21

    $(document).ready(function(){
    $(".chk").click(function(){
    var d = $("input[name=test]"); if(d.is(":checked")){
    //
    }
    });
    });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <input type="checkbox" name="test"> `test1`
    <input type="checkbox" name="test"> `test2`
    <input type="checkbox" name="test"> `test3`
    <input type="button" value="check" class='chk'/>

    0 讨论(0)
  • 2020-11-29 20:22

    Try this

    <input name="selector[]" id="ad_Checkbox1" class="ads_Checkbox" type="checkbox" value="1" />
    <input name="selector[]" id="ad_Checkbox2" class="ads_Checkbox" type="checkbox" value="2" />
    <input name="selector[]" id="ad_Checkbox3" class="ads_Checkbox" type="checkbox" value="3" />
    <input name="selector[]" id="ad_Checkbox4" class="ads_Checkbox" type="checkbox" value="4" />
    <input type="button" id="save_value" name="save_value" value="Save" />
    

    function

        $(function(){
          $('#save_value').click(function(){
            var val = [];
            $(':checkbox:checked').each(function(i){
              val[i] = $(this).val();
            });
          });
        });
    
    0 讨论(0)
提交回复
热议问题