Javascript jquery 1.7.on无法正常工作
我对jquery有一个奇怪的问题, 我有以下代码向表中添加新行: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添加的按钮 我正在
$('#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?:)