zoukankan      html  css  js  c++  java
  • JQuery之ContextMenu(右键菜单)

    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主页:   http://jquery.com/

    插件中的参数说明:
    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. 

    通过此插件可以在不同的html元素内建立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;">
        右键点此
     
    </span>
    <hr />
    <div id="demo2">
        右键点此
    </div>
    <hr />
    <div class="demo3" id="dontShow">
      不显示
    </div>
    <hr />
    <div class="demo3" id="showOne">
      显示第一项
    </div>
    <hr />
    <div class="demo3" id="showAll">
      显示全部
    </div>

    <hr />
        
    <!--右键菜单的源-->
         
    <div class="contextMenu" id="myMenu1">
          
    <ul>
            
    <li id="open"><img src="folder.png" /> 打开</li>
            
    <li id="email"><img src="email.png" /> 邮件</li>
            
    <li id="save"><img src="disk.png" /> 保存</li>
            
    <li id="delete"><img src="cross.png" /> 关闭</li>
          
    </ul>
        
    </div>

        
    <div class="contextMenu" id="myMenu2">
            
    <ul>
              
    <li id="item_1">选项一</li>
              
    <li id="item_2">选项二</li>
              
    <li id="item_3">选项三</li>
              
    <li id="item_4">选项四</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标签都会绑定此右键菜单
         $('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'
          }
    ,
          
    //菜单项样式
          itemStyle: {
            fontFamily : 'verdana',
            backgroundColor : 'green',
            color: 'white',
            border: 'none',
            padding: '1px'

          }
    ,
          
    //菜单项鼠标放在上面样式
          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标签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>
     
     
     
    //------------------------------------------

    关于JQuery的serialize方法.让我崩溃一天的问题解决了

            这几天做一个Ajax像服务器动态提交的表单然后给出即时反馈.这些表单内容都是一系列的.内容大同小异.所以代码和页面结构也是大同小异.但是其中有一个页面使用AJAX始终无法提取到服务器值.反而将此页的整个render出来的页面显示出来.关键代码如下:

     


        $(document).ready(function() {
            $(
    "#Submit").click(function() {
                var a 
    = $("#aspnetForm").serialize();
    /*因为使用了masterpage,所以页面form的ID为aspnetForm*/
                $.ajax({
                  url: 
    "xxx.aspx",
                  type: 
    "get",
                  data: a,
                  success: function(data){
                    $(
    "#result").html(data);
                  }
                });
            });
        });
        

    后台代码简略如下.只是为了让大家明白意思:

     


        protected void Page_Load(object sender, EventArgs e)
        {
            
    if (Request.QueryString["length"!= null)
            {
                Response.Clear();
                Response.Write(
    "这里是回传的数据");
                Response.End();
            }
           
        }
  • 相关阅读:
    数据分析系统DIY1/3:CentOS7+MariaDB安装纪实
    NSArray与NSString、NSData,NSDictionary与NSString、NSData 相互转化
    Geek地生活,文艺地思考
    Android开发中遇到的问题(五)——Eclipse导入Android项目出现"Invalid project description overlaps the location of another project"错误的解决办法
    Android开发中遇到的问题(四)——Android中WARNING: Application does not specify an API level requirement!的解决方法
    Android开发中遇到的问题(三)——eclipse创建android项目无法正常预览布局文件
    Android开发中遇到的问题(二)——新建android工程的时候eclipse没有生成MainActivity和layout布局
    Android开发学习总结(三)——appcompat_v7项目说明
    Android开发学习总结(二)——使用Android Studio搭建Android集成开发环境
    Android开发学习总结(一)——搭建最新版本的Android开发环境
  • 原文地址:https://www.cnblogs.com/fx2008/p/2284396.html
Copyright © 2011-2022 走看看