jquery li元素id
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用
"#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 ofli
element > subelement
is for direct children of the element only. in this case, the direct child of#mailbox
would probably beul
and notli
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