如何让 jQuery .live() 和 .expander 一起正常运行?
我在让 .expander 处理包含动态 jQuery 数据的 div 时遇到问题(即在加载 DOM 之后)。一位用户确实建议尝试 .live() ,这让我更近了一步,但它产生了一些奇怪的情况,如下图所示。
我提到了一个单独的问题,其中 https://stackoverflow.com/users/830804/eric 建议我尝试。居住(): 如何获取扩展器函数来处理动态 jQuery 数据?
注意:幻灯片 1-4 位于我之前的问题:
幻灯片 5-6 见下文。
幻灯片 5: 使用 .live() 的 UI创建一个每个模块中的 exandable/collapsable div
SLIDE 6: 在 div 上点击几次的结果...它添加了多个折叠链接
SLIDE 7: 使用 .live 的功能() 来定位动态 jQuery 数据
感谢您提供的任何建议。
I have been having issues with getting .expander to work with divs that contain dynamic jQuery data (i.e. after the DOM is loaded). A user did recommend trying .live() and that has gotten me a step closer but it is creating some weirdness as illustrated in the images below.
I refer to a separate question in which https://stackoverflow.com/users/830804/eric suggested that I try .live():
How can I get the expander function to work with dynamic jQuery data?
NOTE: Slides 1-4 are located at my previous question here:
How can I get the expander function to work with dynamic jQuery data?
For Slides 5-6 see below.
SLIDE 5: The UI that uses .live() to create an exandable/collapsable div in each module
SLIDE 6: The result of clicking several times on the div... It adds multiple collapse links
SLIDE 7: The function that uses .live() to target dynamic jQuery data
Thanks for any advice you could offer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你最初的答案是错误的。您想要做的是在加载 AJAX 内容后设置扩展绑定,而不是在单击时设置。这是伪代码。
发生的情况是,每次您单击标签隐藏的 div 时,都会调用 .expander。我不确定您何时加载动态数据,但您希望在设置内容后立即绑定扩展器一次,并且仅绑定一次。
如果由于某种原因无法访问 AJAX 回调函数,只需确保仅绑定事件一次。
Your initial answer is wrong. What you want to do is set up an expanded binding once the AJAX content is loaded, not on click. Here's pseudo code.
What's happening is that .expander is getting called every time you click on the tags-hidden div. I'm not sure when you're loading in your dynamic data, but you want to bind expander once, and only once, right after you set the content.
If, for some reason, the AJAX callback function is not accessible, just make sure that you only bind your event once.