ajax 加载后绑定自定义事件处理程序
具体来说,我希望将灯箱绑定到特定元素。通常我会这样做: $('a.lightbox').lightBox();
但这不起作用,因为我正在使用 AJAX 进行一些加载。查看 jQuery API,我发现 .bind()
和 .live()
但当我执行 $('a.lightbox' 时我没有得到任何东西).bind('lightBox')
在 AJAX .load()
调用之后。
我缺少什么?
Specifically I'm looking to bind lightbox to a specific element. Normally I would just do this: $('a.lightbox').lightBox();
but that isn't working since I'm doing some loading with AJAX. Looking at the jQuery API I found .bind()
and .live()
but I'm not getting anything when I do $('a.lightbox').bind('lightBox')
after the AJAX .load()
call.
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要添加一个处理该问题的回调函数。
绑定不会帮助您,因为该事件不会触发事件。
You need to add a callback function that handles that.
Bind isn't going to help you, as the event isn't getting an event fired on it.
另一种方法是绑定到 dom 中较高的元素并检查目标类型。例如:
只是不要走得太远,否则您会捕获太多的点击。
Another way would be to bind to an element higher up in the dom and check the target type. Such as:
Just don't go too far up or you'll be catching way too many clicks.