动态追加的元素绑定不了事件

来源:互联网 发布:好看的日本漫画 知乎 编辑:程序博客网 时间:2024/05/18 09:15

自己的代码:

        $(data).each(function(i){
          var _index=i;
                $(this).bind("click",function(){              
                        sendOneMlistClick(_index,"pn"+ _this.currPageNum,$(this));
                });
                _this.node.append($(this));
        });

                $(".infolst").find(".infolstmore:last-child").on("click","li",function(){              
                        sendOneMlistClick("pn"+ currPageNum,$(this));
                });



网上的解决方案

jquery 1.7版以后使用on动态绑定事件

$("#testdiv ul").on("click","li", function() {

//do something here

});


0 0