<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    我的漫漫程序之旅

    專注于JavaWeb開(kāi)發(fā)
    隨筆 - 39, 文章 - 310, 評(píng)論 - 411, 引用 - 0
    數(shù)據(jù)加載中……

    JQuery之ContextMenu(右鍵菜單)

     

    插件下載地址:
    http://www.trendskitchens.co.nz/jquery/contextmenu/jquery.contextmenu.r2.js
    壓縮版:
    http://www.trendskitchens.co.nz/jquery/contextmenu/jquery.contextmenu.r2.packed.js

    Jquery主頁(yè):   http://jquery.com/

    插件中的參數(shù)說(shuō)明:
    Parameters
    menu_id
    The id of the menu as defined in your markup. You can bind one or more elements to a menu. Eg $("table td").contextMenu("myMenu") will bind the menu with id "myMenu" to all table cells. 
    Note: This behaviour has changed from r1 where you needed a "#" before the id 

    settings
    ContextMenu takes an optional settings object that lets you style your menu and bind click handlers to each option. ContextMenu supports the following properties in the settings object: 

    bindings 
    An object containing "id":function pairs. The supplied function is the action to be performed when the associated item is clicked. The element that triggered the current menu is passed to this handler as the first parameter. 
    Note: This behaviour has changed from r1 where you needed a "#" before the id 
    menuStyle 
    An object containing styleName:value pairs for styling the containing 
    <ul> menu. 
    itemStyle 
    An object containing styleName:value pairs for styling the 
    <li> elements. 
    itemHoverStyle 
    An object containing styleName:value pairs for styling the hover behaviour of 
    <li> elements. 
    shadow 
    Boolean: display a basic drop shadow on the menu. 
    Defaults to true 
    eventPosX 
    Allows you to define which click event is used to determine where to place the menu. There are possibly times (particularly in IE6) where you will need to set this to "clientX". 
    Defaults to: 'pageX' 
    eventPosY 
    Allows you to define which click event is used to determine where to place the menu. There are possibly times (particularly in IE6) where you will need to set this to "clientY". 
    Defaults to: 'pageY' 
    onContextMenu(event) 
    A custom event function which runs before the context menu is displayed. If the function returns false the menu is not displayed. This allows you to attach the context menu to a large block element (or the entire document) and then filter on right click whether or not the context menu should be shown. 
    onShowMenu(event, menu) 
    A custom event function which runs before the menu is displayed. It is passed a reference to the menu element and allows you to manipulate the output before the menu is shown. This allows you to hide/show options or anything else you can think of before showing the context menu to the user. This function must return the menu. 

    通過(guò)此插件可以在不同的html元素內(nèi)建立contextmenu,并且可以自定義樣式.

    <HTML>
     
    <HEAD>
      
    <TITLE> JQuery右鍵菜單 </TITLE>
      
    <script  src="jquery-1.2.6.min.js"></script>
      
    <script src="jquery.contextmenu.r2.js"></script>
     
    </HEAD>

     
    <BODY>
     
    <span class="demo1" style="color:green;">
        右鍵點(diǎn)此
     
    </span>
    <hr />
    <div id="demo2">
        右鍵點(diǎn)此
    </div>
    <hr />
    <div class="demo3" id="dontShow">
      不顯示
    </div>
    <hr />
    <div class="demo3" id="showOne">
      顯示第一項(xiàng)
    </div>
    <hr />
    <div class="demo3" id="showAll">
      顯示全部
    </div>

    <hr />
        
    <!--右鍵菜單的源-->
         
    <div class="contextMenu" id="myMenu1">
          
    <ul>
            
    <li id="open"><img src="folder.png" /> 打開(kāi)</li>
            
    <li id="email"><img src="email.png" /> 郵件</li>
            
    <li id="save"><img src="disk.png" /> 保存</li>
            
    <li id="delete"><img src="cross.png" /> 關(guān)閉</li>
          
    </ul>
        
    </div>

        
    <div class="contextMenu" id="myMenu2">
            
    <ul>
              
    <li id="item_1">選項(xiàng)一</li>
              
    <li id="item_2">選項(xiàng)二</li>
              
    <li id="item_3">選項(xiàng)三</li>
              
    <li id="item_4">選項(xiàng)四</li>
            
    </ul>
       
    </div>
        
         
    <div class="contextMenu" id="myMenu3">
             
    <ul>
              
    <li id="item_1">csdn</li>
              
    <li id="item_2">javaeye</li>
              
    <li id="item_3">itpub</li>
            
    </ul>
        
    </div>
     
    </BODY>
     
    <script>
        
    //所有class為demo1的span標(biāo)簽都會(huì)綁定此右鍵菜單
         $('span.demo1').contextMenu('myMenu1', 
         
    {
              bindings: 
              
    {
                'open': 
    function(t) {
                  alert('Trigger was '
    +t.id+'\nAction was Open');
                }
    ,
                'email': 
    function(t) {
                  alert('Trigger was '
    +t.id+'\nAction was Email');
                }
    ,
                'save': 
    function(t) {
                  alert('Trigger was '
    +t.id+'\nAction was Save');
                }
    ,
                '
    delete': function(t) {
                  alert('Trigger was '
    +t.id+'\nAction was Delete');
                }

              }


        }
    );
        
    //所有html元素id為demo2的綁定此右鍵菜單
        $('#demo2').contextMenu('myMenu2', {
          
    //菜單樣式
          menuStyle: {
            border: '2px solid #
    000'
          }
    ,
          
    //菜單項(xiàng)樣式
          itemStyle: {
            fontFamily : 'verdana',
            backgroundColor : 'green',
            color: 'white',
            border: 'none',
            padding: '1px'

          }
    ,
          
    //菜單項(xiàng)鼠標(biāo)放在上面樣式
          itemHoverStyle: {
            color: 'blue',
            backgroundColor: 'red',
            border: 'none'
          }
    ,
          
    //事件    
          bindings: 
              
    {
                'item_1': 
    function(t) {
                  alert('Trigger was '
    +t.id+'\nAction was item_1');
                }
    ,
                'item_2': 
    function(t) {
                  alert('Trigger was '
    +t.id+'\nAction was item_2');
                }
    ,
                'item_3': 
    function(t) {
                  alert('Trigger was '
    +t.id+'\nAction was item_3');
                }
    ,
                'item_4': 
    function(t) {
                  alert('Trigger was '
    +t.id+'\nAction was item_4');
                }

              }

        }
    );
        
    //所有div標(biāo)簽class為demo3的綁定此右鍵菜單
        $('div.demo3').contextMenu('myMenu3', {
        
    //重寫onContextMenu和onShowMenu事件
          onContextMenu: function(e) {
            
    if ($(e.target).attr('id') == 'dontShow') return false;
            
    else return true;
          }
    ,

          onShowMenu: 
    function(e, menu) {
            
    if ($(e.target).attr('id') == 'showOne') {
              $('#item_2, #item_3', menu).remove();
            }

            
    return menu;
          }


        }
    );



     
    </script>
    </HTML>
    效果圖:


    posted on 2009-01-06 14:11 々上善若水々 閱讀(66513) 評(píng)論(10)  編輯  收藏 所屬分類: JQuery

    評(píng)論

    # re: JQuery之ContextMenu(右鍵菜單)  回復(fù)  更多評(píng)論   

    樓主你好,能幫忙指出代碼中哪里判斷的點(diǎn)擊的是右鍵 嗎。
    2009-05-22 10:30 | sc

    # re: JQuery之ContextMenu(右鍵菜單)  回復(fù)  更多評(píng)論   

    onContextMenu: function(e) {
    if ($(e.target).attr('id') == 'dontShow') return false;
    else return true;
    },
    2009-05-25 11:48 | supercrsky

    # re: JQuery之ContextMenu(右鍵菜單)  回復(fù)  更多評(píng)論   

    樓主你好:
    能否解釋一下這句的意思:
    $('#'+id, menu).bind('click', function(e)
    如果我不使用xpath方式,用css方式應(yīng)該怎么樣謝謝,
    2009-11-11 05:57 | river

    # re: JQuery之ContextMenu(右鍵菜單)[未登錄](méi)  回復(fù)  更多評(píng)論   

    可否說(shuō)下怎樣實(shí)現(xiàn),含字菜單
    2010-09-28 17:21 | calvin

    # re: JQuery之ContextMenu(右鍵菜單)  回復(fù)  更多評(píng)論   

    你好, $("td").livequery(function (e) {
    var td = $(this);

    $(this).contextMenu('myMenu1', {

    bindings: {

    'factory': function (t) {



    },

    'email': function (t) {

    alert('Trigger was ' + $("#hide1").val() + '\nAction was Email');
    location.href = "location.aspx?trid=" + $("#hide1").val();

    },

    'save': function (t) {

    alert('Trigger was ' + t.id + '\nAction was Save');

    },

    'inv': function (t) {

    alert('Trigger was ' + t.id + '\nAction was Delete');

    },

    'insert': function (t) {

    var a = "<tr><td id='a'></td><td id='b'></td><td></td><td></td><td></td></tr>"
    $("tbody").append(a);

    },

    'delete': function (t) {

    alert(t.id);
    alert($("#hide1").val());

    },

    'color': function (t) {

    var offset = td.offset();


    $("#colorselections").css({
    "top": offset.top + "px",
    "left": offset.left + "px"
    }).show();
    $("#colorselections a").click(function () {
    $(this).addClass("on").parent().siblings().children().removeClass("on");
    alert(td.attr("id"));
    $("#" + td.attr("id")).css("color", $(this).css("background-color"));

    });

    }









    }//binding

    }); //contextMenu

    });
    這是我寫的程序,我想改變td中字體的顏色,可是我改變了一個(gè)td的字體顏色,然后再改變另一個(gè)td的顏色,結(jié)果所有的td的顏色都變成一樣的了。
    2010-12-13 10:34 | wtq

    # re: JQuery之ContextMenu(右鍵菜單)  回復(fù)  更多評(píng)論   

    真歷害,非常感謝師傅
    2010-12-13 21:18 | 小王

    # re: JQuery之ContextMenu(右鍵菜單)  回復(fù)  更多評(píng)論   

    問(wèn)一下就是在右擊的時(shí)候同時(shí)改變div的背景色怎么辦
    2010-12-16 10:33 | re

    # re: JQuery之ContextMenu(右鍵菜單)  回復(fù)  更多評(píng)論   

    樓主,當(dāng)屏蔽右鍵菜單中的一個(gè)菜單時(shí),菜單沒(méi)有辦法操作了,是contextMenu的bug嗎?要如何解決呀?
    2011-05-19 10:42 | linian

    # re: JQuery之ContextMenu(右鍵菜單)  回復(fù)  更多評(píng)論   

    右鍵菜單過(guò)長(zhǎng)時(shí),在稍微靠下位置會(huì)撐開(kāi)頁(yè)面,應(yīng)該怎么解決
    ?謝謝
    2012-01-16 15:56 | ai

    # re: JQuery之ContextMenu(右鍵菜單)  回復(fù)  更多評(píng)論   

    我很急,請(qǐng)幫忙解決一下,謝了!!!
    2012-01-16 15:56 | ai

    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 久久精品亚洲一区二区三区浴池| 免费欧洲美女牲交视频| 最新中文字幕免费视频| 免费网站看v片在线香蕉| 国产一卡二卡≡卡四卡免费乱码| 亚洲午夜日韩高清一区| 亚洲男同帅GAY片在线观看| 中文字幕亚洲精品资源网| 亚洲综合偷自成人网第页色| 精品视频免费在线| 中文字幕视频在线免费观看| 99久久免费国产香蕉麻豆| 日韩a级毛片免费观看| 中文字幕久久亚洲一区| 亚洲网站在线播放| 国产精品亚洲一区二区三区| 你是我的城池营垒免费看| 亚洲w码欧洲s码免费| 国产成人高清精品免费鸭子| 国产A在亚洲线播放| 亚洲欧美日韩综合俺去了| 精品国产污污免费网站入口在线| 69免费视频大片| 免费国内精品久久久久影院| 久久国产亚洲观看| 亚洲精品国产精品| 永久在线观看免费视频| 午夜两性色视频免费网站| 亚洲人JIZZ日本人| 亚洲精品一卡2卡3卡四卡乱码 | 亚洲精品高清视频| 亚洲Av永久无码精品一区二区| 丰满人妻一区二区三区免费视频| 7723日本高清完整版免费| 久久亚洲中文字幕精品一区四| 亚洲天堂一区二区三区| 国产免费高清69式视频在线观看| 最近最新MV在线观看免费高清| 国产亚洲?V无码?V男人的天堂| 精品亚洲成在人线AV无码| 成人无码视频97免费|