1

在 jQuery < 1.5 中获得 live() 和 on() 相同功能的正确方法是什么。

4

3 回答 3

1

从 jQuery 1.7 开始,不推荐使用.live()方法。使用 .on() 附加事件处理程序。旧版本 jQuery 的用户应该使用 .delegate() 而不是 .live()。

.on()适用于 jQuery 1.7 及更高版本。如果您有旧版本,请使用以下命令:

$("#SomeId").live("click",function(){
    //do stuff;
});

但是您可以使用live(),因为您正在使用jQuery<1.5

于 2014-03-03T07:55:17.823 回答
1

您需要使用.delegate

 $( "table" ).delegate( "td", "click", function() {
  alert($(this).html());
});
于 2014-03-03T08:00:43.397 回答
0

使用delegate https://api.jquery.com/delegate/适用于 jQuery 1.4.3+

于 2014-03-03T07:57:26.547 回答