新插入的元素,Colorbox 未附加到正确的事件

发布于 2024-11-09 07:21:18 字数 591 浏览 0 评论 0原文

我有一个表,我想在其中动态添加一行。这部分工作正常,我正在使用 jQuery 插入新行。问题是,该行包含两个“编辑”和“删除”链接,它们附加到 Colorbox 弹出窗口。现有行可以与 Colorbox 配合使用,但新行将两个链接附加到“新用户”Colorbox,而不是相应的“编辑”或“删除”弹出窗口。

另一个奇怪的行为是,一旦您单击任何旧链接,链接就会正确附加。重新创建的步骤:

  1. 单击“添加新人员”
  2. 单击“添加”
  3. 单击新行的“编辑” - 它 显示“添加新用户”颜色框
  4. 单击其中一项的“编辑” 现有行
  5. 现在单击新行的“编辑” - 它正确显示了编辑颜色框

我尝试在 http://pastebin.com/i8n3t2Yt。如果您想在本地计算机上运行它,您必须在 http://colorpowered.com/ 下载 Colorbox JS颜色框/

I have a table where I want to dynamically add a row. This part is working fine and I am using jQuery to insert the new row. The problem is, the row includes two links for 'edit' and 'delete' which are attached to Colorbox popups. Existing rows work fine with Colorbox, but the new rows attach both links to the 'new user' Colorbox, instead of the 'edit' or 'delete' popups as appropriate.

Another strange behavior is that the links are correctly attached once you click on any of the older links. Steps to recreate:

  1. Click on "Add New Person"
  2. Click on "Add"
  3. Click on "Edit" for the new row - it
    shows the Add New User colorbox
  4. Click on "Edit" for one of the
    existing rows
  5. Now click on "Edit" for the new row - it correctly shows the Edit colorbox

I have tried to create the simplest test case possible at http://pastebin.com/i8n3t2Yt. If you want to run it on your local machine you'll have to download the Colorbox JS at http://colorpowered.com/colorbox/.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

太阳男子 2024-11-16 07:21:18

听起来将事件附加到前一行的代码不会在之后执行到新创建的行。您需要显式地重新运行代码,或者将回调附加到添加新行时通知的事件。

[编辑查看代码]

好的,我刚刚查看了您的代码,情况确实如此。您正在使用“就绪”方法,该方法运行一次,然后就是这样 - 此后不会再次触发。因此任何新节点都没有附加回调。

It sounds like the code that attaches events to previous rows is not being executed to newly created ones afterwards. you need to re-run the code either explicitly or attaching a callback to an event that is notified when you add new rows.

[Editor looks at code]

Ok I have just reviewed your code and it is definitely the case. you are using the 'ready' method which runs once and then that's it - It's not triggered again thereafter. SO any new nodes do not have the callback attached.

时光病人 2024-11-16 07:21:18

因为我使用 .clone() 创建新行,所以它不是克隆附加事件。 Clone 有一个可选参数 .clone( [ withDataAndEvents ] ),我相信它以前默认为 true 但在 1.6 中发生了变化。我认为由于 Colorbox 使用 .live() 附加事件,我不需要为 [ withDataAndEvents ] 指定 true,但显然我确实需要这样做。

Because I was creating the new row using .clone(), it wasn't cloning attached events. Clone has an optional parameter .clone( [ withDataAndEvents ] ), which was previously defaulted to true but changed in 1.6, I believe. I thought that since Colorbox used .live() to attach events, I wouldn't need to specify true for [ withDataAndEvents ] but apparently I did need to.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文