Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
click()不适用于ajax jquery_Jquery_Ajax - Fatal编程技术网

click()不适用于ajax jquery

click()不适用于ajax jquery,jquery,ajax,Jquery,Ajax,嗨,我有一个ajax功能,它从服务器端获取数据,并向表行添加append td var str =$(".note-list"); $.ajax({ type: "GET", url: "abc.htm", success: function(msg){ var s="<tr class='fc-staff'>"; alert("s

嗨,我有一个ajax功能,它从服务器端获取数据,并向表行添加append td

 var str =$(".note-list");
$.ajax({    
            type: "GET",
            url: "abc.htm",

            success: function(msg){    
                 var s="<tr class='fc-staff'>";             

alert("success"+str);

            $.each( msg, function(i,value ) {

                     s=s+"<td class='fc-widget-content fc-first'>"+value+"<i      
        class='icon-remove'></i></td> ";


                });
            s=s+"</tr>";
            str.html(s);
            $("#popup").show();
        },
 error : function(e) {
        alert('Error: ' + e);
    }
    });

 });
福伊

附加的源代码即使在视图页面源代码中也不会显示,而是在UI中显示

我的页面来源是

<table class="fc-border-separate note-list" style="width: 100%"
                                    cellspacing="0">
                // Not showing appended td                  
</table>

//不显示附加的td
帮助我让jquery函数为这个附加的td工作


提前感谢

在加载DOM后添加
td
元素时,需要使用委托事件处理程序。试试这个:

$(".note-list").on('click', 'td', function() {
    alert("tdclicked"); // Its not working
    alert($(this).text());
});

在加载DOM后追加
td
元素时,需要使用委托事件处理程序。试试这个:

$(".note-list").on('click', 'td', function() {
    alert("tdclicked"); // Its not working
    alert($(this).text());
});

您正在访问
str=$('.notelist')
,就好像它是唯一的元素一样。您需要在所有具有此类的表上循环。

您正在访问
str=$('.notelist')
,就好像它是唯一的元素一样。您需要在所有具有该类的表上循环。

试试这个

$("table").on('click', 'td', function() {
    alert($(this).text());
});
加载页面后,您将添加元素,因此必须委派
单击事件

有关更多信息,请查看jquery on docs

希望这有帮助

试试这个

$("table").on('click', 'td', function() {
    alert($(this).text());
});
加载页面后,您将添加元素,因此必须委派
单击事件

有关更多信息,请查看jquery on docs


希望这有帮助

@Rory McCrossan说的没错:)你也可以这样做:

$(document).on("click", "#yourTableID td" , function() {
     doStuff();
}); 

@Rory McCrossan说得对:)你也可以这样做:

$(document).on("click", "#yourTableID td" , function() {
     doStuff();
}); 

这个类中没有一个元素,那么为什么不使用id呢?在阅读了所有答案之后,这可能不是代码不工作的原因。但是,至少,当只有一个元素将携带该名称时,使用id而不是类是很好的设计。该类中没有一个元素,那么为什么不使用id呢?在阅读了所有答案后,这可能不是代码无法工作的原因。但是,至少,当只有一个元素将使用该名称时,使用id而不是类是一个很好的设计。Rory McCrossan先生,谢谢你的回答,但它仍然不起作用没有问题,很高兴帮助Rory McCrossan先生,谢谢你的回答,但它仍然不起作用没有问题,很高兴help@run活的被移除actually@runlive()实际上已被删除