jquery li元素id

发布于 2024-08-18 12:15:04 字数 418 浏览 1 评论 0原文

我正在使用 jquery contextmenu 插件来右键单击菜单,我试图将其添加到带有 ID 邮箱的无序列表的每个 li 元素中。我的代码是:

    $("#mailbox > li").contextMenu('myMenu1', {
      bindings: {
    'open': function(t) {
      alert('Trigger was '+t.id+'\nAction was Open');
    }
    //CODE SNIPPED
    });

我的假设是,这应该提醒调用 contextMenu 的列表元素的 id,但它返回一个空字符串。我是否正确访问/分配了这些?

顺便说一句,t 是上面上下文中的 HTMLLIElement 对象。

干杯, 加兹勒。

I am using a jquery contextmenu plugin for right click menus which I am trying to add to each li element of an unordered list with the ID mailbox. The code I have is:

    $("#mailbox > li").contextMenu('myMenu1', {
      bindings: {
    'open': function(t) {
      alert('Trigger was '+t.id+'\nAction was Open');
    }
    //CODE SNIPPED
    });

My assumption is that this should alert the id of the list element that the contextMenu was called from, however it is returning an empty string. Am I accessing/assigning these correctly?

t is an object HTMLLIElement in the context above by the way.

Cheers,
Gazler.

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

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

发布评论

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

评论(1

情绪失控 2024-08-25 12:15:04

尝试使用 "#mailbox li" 作为选择器。原因是 #mailbox 没有任何 li

element > 的子元素。 subelement 仅适用于该元素的直接子元素。在这种情况下,#mailbox 的直接子代可能是 ul,而不是孙代的 li。 element subelement 选择所有后代,而不仅仅是直接子元素。

在这里查看:http://docs.jquery.com/Selectors/child#parentchild
在这里:
http://docs.jquery.com/Selectors/descendant#ancestordescendant

try using "#mailbox li" as your selector. the reason is that #mailbox doesn't have any children of li

element > subelement is for direct children of the element only. in this case, the direct child of #mailbox would probably be ul and not li which would be a grand child. element subelement selects all descendants, not just the direct children.

check it out here: http://docs.jquery.com/Selectors/child#parentchild
and here: http://docs.jquery.com/Selectors/descendant#ancestordescendant

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