Dynamic 无法“选中”动态创建的复选框jQuery

Dynamic 无法“选中”动态创建的复选框jQuery,dynamic,checkbox,jquery,Dynamic,Checkbox,Jquery,我正在创建一个模式弹出窗口,并动态地向其中添加一些数据,以及几个复选框。有一个复选框可以选择某个部分中的所有复选框,它可以正常工作,除了“全选”复选框在我双击它之前不会被选中,这实际上会使click函数运行两次 $('#delAllSampleTwo').live('click',function(){ $('.delAllSampleTwo').prop("checked", !$('.delAllSampleTwo').prop("checked"));

我正在创建一个模式弹出窗口,并动态地向其中添加一些数据,以及几个复选框。有一个复选框可以选择某个部分中的所有复选框,它可以正常工作,除了“全选”复选框在我双击它之前不会被选中,这实际上会使click函数运行两次

$('#delAllSampleTwo').live('click',function(){
            $('.delAllSampleTwo').prop("checked", !$('.delAllSampleTwo').prop("checked"));
            $('.delTwo').prop("checked", !$('.delTwo').prop("checked"));
        });
.delTwo类代码工作正常。但不是delAllSampleTwo,是的,它们的ID和类是相同的,我尝试了使用ID或类,但无法使其正常工作

下面是从JQuery代码返回的HTML字符串

    <table style=\'width: 685px;\' cellpadding=\'0\' cellspacing=\'0\'>
    <tr>
        <td style=\'width:20px;\'><a href=\'#\' class=\'toggleReportTwo\'></a></td>
        <td style=\'width:315px; text-align:left; font-weight:bold;\'>Sample Report Two</td>
        <td style=\'font-weight:bold; width:140px; text-align:right;\'>10/3/2013,9:52:40 AM</td>
        <td style=\'font-weight:bold; width:150px; text-align:left; padding-left:6px;\'>
            <a href=\'#\' class=\'viewIndReports\'>View All in One PDF</a>
        </td>
        <td style=\'width:70px;\'>
            <input type=\'checkbox\' id=\'delAllSampleTwo\' class=\'delAllSampleTwo\'/>All
        </td>
    </tr>
</table>
<div id=\'sampleTwoReports\'>
    <table style=\'width: 685px;\' cellpadding=\'0\' cellspacing=\'0\'>
        <tr>
            <td style=\'width:20px;\'></td>
            <td style=\'width:315px; text-align:left;\'>CHIN KIM</td>
            <td style=\'width: 140px; text-align:right; padding-right:4px;\'>&nbsp;</td>
            <td style=\'width:150px; text-align:left; padding-left:6px;\'>
                <a class=\'viewIndReports\' href=\'#\' target=\'_blank\'>View</a>
            </td>
            <td style=\'width:70px;\'>
                <input type=\'checkbox\' id=\'delCHIN KIM\' class=\'delTwo\'/>
            </td>
        </tr>
    </table>
</div>

我明白了,这就是我最后要做的。首先,我读了一些帖子,内容是关于当动态地向一个模态添加元素时,z-index可能会被丢弃,从而失去功能,因此我将模态z-index设置为99999,并将函数重写为

$('.delAllSampleTwo').live('click',function(){
                if($(this).is(":checked")){
                    $('.delTwo').prop("checked",true);
                }else{
                    $('.delTwo').prop("checked",false);
                }

做得很好。

试试$'delAllSampleTwo'。实时“点击”,函数{$'.delAllSampleTwo.delTwo.propchecked,this.checked;};你能分享一个html示例吗?虽然看起来不起作用,但我用html交付的DynamicAllyal更新了帖子。因此,如果这有什么不同的话,它会动态添加到一个模式窗口中