在 jQuery 中使用 .live 时无意中执行的函数
我正在尝试将单击事件处理程序绑定到动态创建的某些元素。 但该函数在加载页面时就已经被执行了。 我还尝试了 livequery 插件和 .delegate,它们也有这种不受欢迎的习惯。
$(".pika_thumb").live("click" ,( function () {
$("#video").hide();
$(".pika_main").show();
}));
如何防止我的函数在单击指定元素之外的其他事件上执行?
I'm trying to bind a click event handler to some elements that are being created dynamically.
But the function already gets executed on simply loading the page.
I also tried the livequery plugin and .delegate which also had that unwanted habit.
$(".pika_thumb").live("click" ,( function () {
$("#video").hide();
$(".pika_main").show();
}));
How do I prevent my function to be executed on other events than a click on the specified elements?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
唯一明显的错误是
function() { }
定义周围的括号。但是,除非您也有尾随
()
参数列表,否则这不会导致立即调用。你的代码片段完整吗?The only obvious error is the brackets from around the
function() { }
definition.However that wouldn't cause immediate invocation unless you had trailing a
()
parameter list too. Is your code snippet complete?语法:
检查是否没有其他东西可以触发 .pika_thumb 类上的点击。
the syntax:
check if you don't have something else that fires the click on your .pika_thumb class.
除了括号之外,我最终的工作代码是:
谢谢大家!
Aside from the brackets, my final working code is:
Thanks everyone!