jQuery .on与.live [英] Jquery .on versus .live
问题描述
我知道 .live()
现在已被弃用,但我似乎无法对其进行更改并保留其功能.
I know that .live()
is now deprecated but I cannot seem to change it and keep the functionality.
我只是对jQuery中的.on()
函数有一个简单的问题.我目前正在.live()
此处
I just have a quick question about the .on()
function in jQuery. I'm currently using .live()
here
像这样:
$('table tr th').live("click", function() {
});
但是,当我尝试用.on()
替换.live()
时,它不再按预期工作.
But, when I try and replace .live()
with .on()
it no longer works as it's supposed to.
我尝试放入
$('table tr th').on("click", function() {
});
以及
$('table tr').live("click", "th", function() {
});
和
$('table tr').delegate("th", "click", function() {
});
但无济于事.
这是为什么,我应该采取什么步骤使其正常工作?
Why is this and what steps can I take to make it work properly?
推荐答案
on()
函数需要语法更新,您应该将代码更改为:
The on()
function requires a syntactical update, you should alter your code to:
$('body').on("click", "table tr th", function()...
查看此文章以获取更多信息: http://www .andismith.com/blog/2011/11/on-and-off/
Check out this article for more info: http://www.andismith.com/blog/2011/11/on-and-off/
这篇关于jQuery .on与.live的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!