在Jquery代码中使用变量

时间:2016-11-10 06:51:50

标签: jquery html contextmenu

如何在此代码中使用EditPhoto变量? 我在这里添加完整的代码。 我如何在这里使用EditPhoto变量: ** EditPhoto:{name:"编辑此照片",图标:"编辑"} **

$(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'));

    });

2 个答案:

答案 0 :(得分: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
    });

答案 1 :(得分: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'));
    });