Get a list of all checked values

后端 未结 3 770
梦如初夏
梦如初夏 2021-01-26 04:30

I have a bunch of radio boxes on my HTML page. Somewhat like this:




        
相关标签:
3条回答
  • 2021-01-26 05:11
    $( '#my-button-id' ).click( function() {
        var tmp = '';
        $( '.custom:checked' ).each( function() {
            // Do what you want...
            tmp += ' ' + $( this ).val();
        });
        alert( tmp );
    });
    
    0 讨论(0)
  • 2021-01-26 05:15

    The following will put the value of the value attribute for each selected radio button into the arr Array:

    var arr = [];
    $(".custom:checked").each(function () {
        arr.push($(this).val());
    });
    
    0 讨论(0)
  • 2021-01-26 05:16

    Try this code

    $('#buttonId').click( function() {
        var result = '';
        $('input:checked').each(function() {
            result += ',' + $(this).val();
        });
        alert(result);
    });
    
    0 讨论(0)
提交回复
热议问题