[英]jquery contextmenu - how to use contextmenu action to get id of the clicked item in the menu
我正在使用jquery contextmenu插件 ,这是我的DEMO
下面是我的代码:
<script type="text/javascript">
$(function () {
$.contextMenu({
selector: '.context-menu-one',
callback: function (key, options) {
var m = "clicked: " + key;
window.console && console.log(m) || alert(m);
alert("Clicked on " + key + " on element " + options.$trigger.attr('id').substr(3));
},
items: {
"edit": { "name": "Edit", "icon": "edit" },
"fold1": {
"name": "Apply for Section",
"items": {
"Section I": { "name": "Section I" },
"Section II": { "name": "Section II" },
"Section III": { "name": "Section III" }
}
},
"fold2": {
"name": "Sub group",
"items": {
"fold1-key1": { "name": "Foo bar" },
"fold2": {
"name": "Sub group 2",
"items": {
"fold2-key1": { "name": "Sub group 1" },
"fold2-key2": { "name": "Sub group 2" },
"fold2-key3": { "name": "Sub group 3" }
}
},
"fold1-key3": { "name": "delta" }
}
},
"fold1a": {
"name": "Other group",
"items": {
"fold1a-key1": { "name": "Other group1" },
"fold1a-key2": { "name": "Other group2" },
"fold1a-key3": { "name": "Other group3" }
} } } }); });
cshtml页面
@foreach(var id in data)
{
<div class="context-menu-one">
<input type="hidden" id="txtID" value="@id">
</div>
<br/>
}
使用上下文菜单
题
1)我想从txtID
菜单中单击任何菜单时获取txtID
,因为它的id
帮助我了解数据库中的哪一行更新?
2)我有三个表Section
Sub group
Other group
因此,当单击section部分更新数据库中的Section
表时,与其他两个表相同。 我想从“ Section
或“ Sub group
或“ Other group
获取哪个子菜单,那么如何获得它?
对于第一个问题,请看一下options.$trigger
。 这是激活上下文菜单的元素。 你可以做:
var el = options.$trigger;
var id = el.attr('id');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.