2017-08-02 230 views
2

我使用jquery contextmenu plugin菜單,這裏是我的DEMOjQuery的文本菜單 - 如何使用文本菜單操作來獲取點擊的項目的ID在

下面是我的代碼:

<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)我有三個表SectionSub groupOther group所以當點擊部分更新Section表中的數據庫與其他兩個表相同時。我想要獲得從SectionSub groupOther group 中點擊哪個子菜單,那麼如何獲取它?

回答

0

對於你的第一個問題,看看options.$trigger。這是激活上下文菜單的元素。 你可以做:

var el = options.$trigger; 
var id = el.attr('id'); 
相關問題