问题描述
我正在使用Bootstrap 3.0 ContextMenu.这是链接 http://jsfiddle.net/KyleMit/X9tgY/
I am using Bootstrap 3.0 ContextMenu. here is a link http://jsfiddle.net/KyleMit/X9tgY/
我需要知道如何获取被单击元素的ID或数据ID.我尝试了许多技巧,但我无法获得单击的元素ID?就像我单击"Jacob"行时一样,单击后得到"Jacob".我还需要此行<td data-id="user-3"> <a data-id="user-3">Jacob<a/> <td/>
数据ID"?
I need to know how i can get the id or data-Id of the clicked element. i try many of the tricks but i cant get the clicked element id? Like when i clicked on "Jacob" row i get the "Jacob" after clicked. I also need from this line<td data-id="user-3"> <a data-id="user-3">Jacob<a/> <td/>
"data-Id"?
我尝试了var $selectedFileId = $(this).closest('a').html();
或alert($(this).parent('a').html());
推荐答案
我通过在contextMenu处理程序更改"中添加一些内容来获得ID
I get the id by little additions in the contextMenu handler, Changes
// click handler for context menu
function ContextMenuClickHandler() {
$(settings.menuSelector)
.off('click')
.on('click', function (e) {
$(this).hide();
var $invokedOn = $(this).data("invokedOn");
var $selectedMenu = $(e.target);
// My Changes
var $selectedFileId = $(this).data("invokedOn").find('.yourClass').attr('id');
settings.menuSelected.call($(this), $invokedOn, $selectedMenu, $selectedFileId);
});
}
这篇关于如何获取"invokedOn"之类的ID通过Bootstrap ContextMenu右键单击事件输入文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!