Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/419.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
Javascript jquery 1.7.on无法正常工作_Javascript_Jquery - Fatal编程技术网

Javascript jquery 1.7.on无法正常工作

Javascript jquery 1.7.on无法正常工作,javascript,jquery,Javascript,Jquery,我对jquery有一个奇怪的问题, 我有以下代码向表中添加新行: $('#converastions_list tr:first').after(append_html); 它添加了一个按钮: <input id="chat_98" class="answerChat btn" value="answer" conversation-id="98" rep-email="xxx" type="button"> 这适用于通过PHP加载的按钮,但不适用于我通过JS添加的按钮 我正在

我对jquery有一个奇怪的问题, 我有以下代码向表中添加新行:

$('#converastions_list tr:first').after(append_html);
它添加了一个按钮:

<input id="chat_98" class="answerChat  btn" value="answer" conversation-id="98" rep-email="xxx" type="button">
这适用于通过PHP加载的按钮,但不适用于我通过JS添加的按钮

我正在使用jquery1.7。有人知道为什么会这样吗

谢谢

即使您正在使用,您也没有使用
.on()
的事件委派格式

当执行脚本时,事件应该绑定到dom中已经存在的元素,并且目标元素的选择器必须作为第二个参数传递

$('#converastions_list tr:first').on("click", ".answerChat", function() {
    alert("clicked");  
});
即使您正在使用,也没有使用
.on()
的事件委派格式

当执行脚本时,事件应该绑定到dom中已经存在的元素,并且目标元素的选择器必须作为第二个参数传递

$('#converastions_list tr:first').on("click", ".answerChat", function() {
    alert("clicked");  
});

使用
.on()
类似的方法尝试
事件定义

$('#converastions_list tr:first').on("click", ".answerChat", function() {
    alert("clicked");  
});

使用
.on()
类似的方法尝试
事件定义

$('#converastions_list tr:first').on("click", ".answerChat", function() {
    alert("clicked");  
});

对动态创建的元素尝试此操作

$(document).on("click",".answerChat",function() {
    alert("clicked");  
});
或者在添加html后写入
单击事件
,如

$('#converastions_list tr:first').after(append_html);
$(".answerChat").on("click",function() {// add after appending anserChat element
    alert("clicked");  
});

对动态创建的元素尝试此操作

$(document).on("click",".answerChat",function() {
    alert("clicked");  
});
或者在添加html后写入
单击事件
,如

$('#converastions_list tr:first').after(append_html);
$(".answerChat").on("click",function() {// add after appending anserChat element
    alert("clicked");  
});

为什么不直接更新到jquery 1.10.2?:)为什么不直接更新到jquery 1.10.2?:)