输出复选框选中的文件名 checkbox

1.

<tr>
        <td><input  type="checkbox" name="cbxFileName"/></td>
        <td>SW_Notice</td>
    </tr>
    <tr>
        <td><input  type="checkbox" name="cbxFileName"/></td>
        <td>SH_Notice</td>
    </tr>
     <tr>
        <td><input id="btnTestcbx" type="button" value="Testcbx"  onclick="Testcbx()"/> </td>
        <td></td>
    </tr>

  function Testcbx()     {         //输出复选框选中的文件名         var arr = new Array();         var length = $("input[name='cbxFileName']:checked").length;   

      if (length == 0)         {             alert("请选中一个文件名");             return;         }

        var i = 0;         $("input[name='cbxFileName']:checked").each(function (index,item) {            // alert($(item).parent().next().text());

            arr[i++] =  $(item).parent().next().text();        

})

        var pFList = arr.join(",");         alert(pFList);   

  }

 2.

//单个复选框判断是否选中  if ($("#IsChangePassword").is(":checked")) {}

3.选择所有的复选框checkbox

$(":checkbox").each(function(index,item){

    $(item).attr("checked",false);

})

另外一种写法:

$("input[type='checkbox']").each(function () {

                     if ($(this).attr("checked")==true)    {  }     

                    //在这里不能用if($(this).is(":checked")){ }   这个写法只能用在radiobutton上面

})

原文地址:https://www.cnblogs.com/sxjljj/p/8533305.html