页面中点击鼠标右键----弹出与windows界面相似的菜单


所属类别:Asp

文章作者:未知

特别推荐:免费发布信息 承包关键词~~抢爆了!HOT!


想在Web Form中做出与windows中相似的菜单,可是发帖问人又没人回,自己摸索郁闷了一天之后,终于在MSDN中找到了相似的方法,具体如下:(下面的代码帖到记事本能直接运行查看)<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">oncontextmenu Event Sample<!--设置菜单的背景样式-->.menuItem {font-family:sans-serif;font-size:10pt;width:100;padding-left:20; background-Color:menu;color:black}.highlightItem {font-family:sans-serif;font-size:10pt;width:100;padding-left:20; background-Color:highlight;color:white}.clickableSpan {padding:4;width:500;background-Color:blue;color:white;border:5px gray solid}//<!--//弹出菜单:function displayMenu() { whichDiv=event.srcElement; menu1.style.leftPos+=10; menu1.style.posLeft=event.clientX; menu1.style.posTop=event.clientY; menu1.style.display=""; menu1.setCapture();}//高亮显示鼠标移上是菜单的背景function switchMenu() { el=event.srcElement; if (el.className=="menuItem") { el.className="highlightItem"; } else if (el.className=="highlightItem") { el.className="menuItem"; }}//点击菜单相应项时触发相应的事件function clickMenu() { menu1.releaseCapture(); menu1.style.display="none";

//点击后隐藏菜单 el=event.srcElement; if (el.id=="mnuRed") { whichDiv.style.backgroundColor="red"; } else if (el.id=="mnuGreen") {

whichDiv.style.backgroundColor="green";

//选择Green时背景变为绿色 } else if (el.id=="mnuBlue") { whichDiv.style.backgroundColor="blue"; //选择blue时背景变为蓝色 } else if (el.id=="mnuYellow") { whichDiv.style.backgroundColor="yellow"; //选择yellow时背景变为黄色 }}//--><!-- SAMPLE_STYLE_START --><!-- SAMPLE_STYLE_END -->PRE.clsCode { font-size:110%; } PRE.clsSyntax { font-size:100%; } TD DIV.clsBeta { display:none;} MSHelp\:link { color:#0000ff; text-decoration:underline; cursor:hand; hoverColor:#3366ff; filterString: ;}<!-- TOOLBAR_START --><!-- TOOLBAR_EXEMPT --><!--TOOLBAR_END--><!-- CONTENTS_START -->oncontextmenu Event SampleThis sample shows how to use the oncontextmenu event handler, available in Microsoft® Internet Explorer 5 and later, to display both standard and custom context menus and prevent context menus from displaying. Experiment with each of the following boxes to see how you can apply different methods either to display or to inhibit context menus. Each box provides instructions for you to follow.1. The default context menu always displays when you right-click in this box.Code: //no code necessary2. The default context menu displays only if you right-click in this box while holding down the Ctrl key. This is useful for developing and debugging purposes.Code: oncontextmenu="return event.ctrlKey"3. A context menu never displays when you right-click in this box.Code: oncontextmenu="return false"4. A custom context menu displays when you right-click in this box.Code: oncontextmenu="showMenu();return false;"5. A custom menu displays when you right-click in this box. If you right-click while holding down the Ctrl key, the default context menu displays.Code: oncontextmenu="if (!event.ctrlKey){displayMenu();return false;}"RedGreenBlueYellow<!-- CONTENTS_END --><!-- START_PAGE_FOOTER -->© 2003 Microsoft Corporation. All rights reserved..<!-- END_PAGE_FOOTER -->

毕竟是MSDN,几乎是要什么有什么有什么啊.经过这次打击后,总结出经验:不会的东西不要很快就去问别人,靠自己摸索其实一样能找出另你满意的答案.

不过还有一点很重要的是要学会查MSDN,输入的关键字要命中要害,可以说应该要一针见血.还有实在找不出的时候,就去查看目录,一级一级的往下找,总能找到你想要的.关闭本页

相关信息

· date修改日期与时间

·  sqlalchemy中文问题解决方案

· Visual C

· Cisco 路由器配置语句汇总








....

106859 48960