How to retrieve checkboxes values in jQuery

前端 未结 15 2343
时光说笑
时光说笑 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 11:09

       $(document).ready(function() {
            $(':checkbox').click(function(){
               var cObj = $(this);
               var cVal = cObj.val();
               var tObj = $('#t');
               var tVal = tObj.val();
               if( cObj.attr("checked")) {
                  tVal = tVal + "," + cVal; 
                  $('#t').attr("value", tVal);
               } else {
                  //TODO remove unchecked value.
               }
            });
        });
    

提交回复
热议问题