gpt4 book ai didi

javascript - jquery contextmenu - 如何使用 contextmenu Action 获取菜单中被点击项目的 id

转载 作者:行者123 更新时间:2023-11-28 02:39:03 32 4
gpt4 key购买 nike

我正在使用 jquery contextmenu plugin这是我的 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" }
} } } }); });

enter image description here

cshtml页面

@foreach(var id in data)
{
<div class="context-menu-one">
<input type="hidden" id="txtID" value="@id">
</div>
<br/>
}

使用上下文菜单

问题

1) 我想在单击上下文菜单中的任何菜单时获取 txtID,因为它的 id 帮助我了解数据库中的哪一行更新?

2) 我有三个表 Section Sub group Other group 所以当点击 section part update Section数据库中的表与其他两个表相同。我想从 SectionSub groupOther group 中获取哪个子菜单点击 那么如何获取呢?

最佳答案

对于第一个问题,请查看 options.$trigger。这是激活上下文菜单的元素。你可以这样做:

 var el = options.$trigger;
var id = el.attr('id');

关于javascript - jquery contextmenu - 如何使用 contextmenu Action 获取菜单中被点击项目的 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45459230/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com