2015-08-28 50 views
0

对不起我的英文不好我附上用ajax新的数据这样的Javascript附加数据不能正常工作的功能

<span class="commentbuton" id="143">Comment..</span> 

和JavaScript是

$(function(){ 
    $(".commentbuton").click(function() { ... 

,但它不是新的附加数据的工作,请帮助表示感谢。

+0

好的,谢谢ı解决我是否需要删除该问题? –

回答

0

将元素插入页面后,需要绑定点击侦听器。我的猜测是你在“.commentbutton”存在之前绑定了点击处理程序。

$('body').html('<div class="commentbutton"></div>') 
//bind after commentbutton inserted 
$(".commentbuton").click(function() { ... }); 

这有帮助吗?

+0

$(document).on(“click”,'.classname',function(){ ı解决这个谢谢.. –