2016-11-10 81 views
1

如何在此代碼中使用EditPhoto變量? 我在這裏添加我的完整代碼。 如何使用EditPhoto變量在這裏: ** EditPhoto:{名稱: 「這張相片進行編輯」 圖標: 「編輯」} **使用變量的jquery代碼

$(document).ready(function() { 
     $('#sortable li').click(function() { 
      id = $(this).attr("id"); 
      id = id.replace("GaleriSirala_", ""); 
      alert(idBul); 
      EditPhoto = ("edit-photo&EditNow=" + id); 
     }); 
    }); 

    $(function() { 
     $.contextMenu({ 
      selector: '.context-menu-one', 
      callback: function(key, options) { 
       var m = "index.php?sayfa=" + key; 
       $(location).attr('href', m) 
      }, 
      items: { 
       EditPhoto :{name: "Edit This Photo", icon: "edit"}, 
      } 
     }); 

     $('.context-menu-one').on('click', function(e){ 
      console.log('clicked', this); 
     }) 
    }); 

    $j('.GaleriListele').click(function() { 

     alert($(this).childen('a').attr('id')); 

    }); 
+0

要在哪裏使用EditPhoto? – Satpal

+0

在這裏:項目:{ EditPhoto:{name:「編輯這張照片」,圖標:「編輯」}, } – Dogan

+1

你確定你想用它作爲屬性名嗎? 'edit-photo&EditNow = id'看起來像一個URL參數字符串,爲什麼會是一個屬性名稱? – Barmar

回答

0

使用[]符號:

試像這樣的東西

var items = {} 

EditPhoto = ("EditPhoto&EditNow=" + id); 

items[EditPhoto] = {name: "Edit This Photo", icon: "edit"} 
$(function() { 
    $.contextMenu({ 
     selector: '.context-menu-one', 
     callback: function(key, options) { 
      var m = "index.php?page=" + key; 
      $(location).attr('href', m) 
     }, 
     items: items 
    }); 
+0

嗨,這是行不通的,然後我在頂部添加我的完整代碼..如何在我的代碼中使用EditPhoto變量? – Dogan

+0

你的意思是什麼沒有被喚醒? – madalinivascu

+0

我不能這樣做。 – Dogan

0

我嘗試這樣。 但右鍵單擊上下文菜單即可打開。

var items = {} 
    EditPhoto = ("EditPhoto&EditNow=" + id); 
    items[EditPhoto] = {name: "Edit This Photo", icon: "edit"} 
    $(function() { 
     $.contextMenu({ 
      selector: '.context-menu-one', 
      callback: function(key, options) { 
       var m = "index.php?sayfa=" + key; 
       $(location).attr('href', m) 
      }, 
      items: items 
     }); 
    }); 
    $j('.GaleriListele').click(function() { 
     alert($(this).childen('a').attr('id')); 
    });