jquery获得复选框checkbox中选中的值

       Html代码:

       

    <input type="checkbox" name="test" value="1">1
    <input type="checkbox" name="test" value="2">2
    <input type="checkbox" name="test" value="3">3
    <input type="checkbox" name="test" value="4">4
    <input type="checkbox" name="test" value="5">5

        

    jquery获得复选框checkbox中选中的值:

   

var checked = $('input:checkbox[name=test]:checked');

checked.each(function () {
      console.log($(this).val());//$(this).val()即为选中的一个复选框的值
});

//或者
for(var i in checked){
      console.log($(checked[i]).val());//$(checked[i]).val()即为选中的一个复选框的值
}

      

     

猜你喜欢

转载自cocoding.iteye.com/blog/2304892