jquery获取所有选中的checkbox


获取所有name为spCodeId的checkbox

     var spCodesTemp = "";
      $('input:checkbox[name=spCodeId]:checked').each(function(i){
       if(0==i){
        spCodesTemp = $(this).val();
       }else{
        spCodesTemp += (","+$(this).val());
       }
      });
      $("#txt_spCodes").val(spCodesTemp);

以类型查找

$("input[type='checkbox'][checked]")

以名称查找

$("input:checkbox[name='the checkbox name']:checked") 

//如果是在某一些标签下查找的话,为了防止查找到table #tbTemplate元素以外的checkbox:checked,我们可以这样来限制:

$("table#tbTemplate input:checkbox[name='the checkbox name']:checked")  

原生态的用法

 

$($("table#tbTemplate input[type='checkbox']"),function(i,checkbox){

     if(checkbox.checked){

          // keep the state. or log this checked......

     }

});

判断多选框是否有选中

if (!$("input[type='checkbox']").is(':checked')) {
    $('#sitetable').hide();
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM