CeiWCJ 2011-09-28
代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <%-- --%> <script src="Script/jquery.js" type="text/javascript"></script> <script src="Script/jquery.contextmenu.r2.js" type="text/javascript"></script> <style type="text/css"> .SelectedRow { background: yellow; } .contextMenu { display: none; } </style> <script type="text/javascript"> $(function() { $('#GridView1 tr:gt(0)').contextMenu('menu', { bindings: { 'add': function(t, target) { alert('Trigger:' + t.id + ' 增加' + " taget by:" + $("td:eq(0)", target).text()); }, 'delete': function(t, target) { alert('Trigger:' + t.id + ' 删除' + " taget by:" + $("td:eq(0)", target).text()); $(target).remove(); }, 'save': function(t, target) { alert('Trigger:' + t.id + ' 保存' + " taget by:" + $("td:eq(0)", target).text()); }, 'About': function(t, target) { alert('Code by http://www.cnblogs.com/whitewolf/'); } }, onShowMenu: function(e, menu) { if (parseInt($("td:eq(0)", e.currentTarget).text()) > 10) { $("#save", menu).remove(); } $(e.currentTarget).siblings().removeClass("SelectedRow").end().addClass("SelectedRow"); return menu; } }); }) </script> </head> <body> <form id="form1" runat="server"> <div> <div class="contextMenu" id="menu"> <ul> <li id="add"> <img src="image/Home_Age_UnSelect.jpg" width="16" height="16" /> 编辑</li> <li id="delete"> <img src="image/Home_Age_UnSelect.jpg" width="16" height="16" /> 删除</li> <li id="save"> <img src="image/Home_Age_UnSelect.jpg" width="16" height="16" /> 保存</li> <li id="About"> <img src="image/Home_Age_UnSelect.jpg" width="16" height="16" /> 关于</li> </ul> </div> <asp:GridView ID="GridView1" runat="server" Width="100%" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3"> <RowStyle ForeColor="#000066" /> <FooterStyle BackColor="White" ForeColor="#000066" /> <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" /> <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" /> </asp:GridView> </div> </form> </body> </html>
代码如下:
'add': function(t, target) { alert('Trigger:' + t.id + ' 增加' + " taget by:" + $("td:eq(0)", target).text()); },
代码如下:
if (!!cur.onShowMenu) menu = cur.onShowMenu(e, menu); $.each(cur.bindings, function(id, func) { $('#' + id, menu).bind('click', function(e) { hide(); func(trigger, currentTarget); }); });
代码如下:
if (!!cur.onShowMenu) menu = cur.onShowMenu(e, menu); $.each(cur.bindings, function(id, func) { $('#' + id, menu).bind('click', function(ev) { hide(); func(trigger, e.currentTarget); }); });