How to retrieve checkboxes values in jQuery

前端 未结 15 2009
时光说笑
时光说笑 2020-11-22 10:11

How to use jQuery to get the checked checkboxes values, and put it into a textarea immediately?

Just like this code:


  
  &l         


        
15条回答
  •  隐瞒了意图╮
    2020-11-22 10:47

    Thanks altCognito, your solution helped. We can also do this by using name of the checkboxes:

    function updateTextArea() {         
       var allVals = [];
       $('[name=chkbox]:checked').each(function() {
          allVals.push($(this).val());
       });
       $('#t').val(allVals)
    } 
    $(function() { 
        $('#c_b input').click(updateTextArea);
        updateTextArea();
    });
    

提交回复
热议问题