Javascript:鼠标事件(转贴)
2005-02-25 11:03
387 查看
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns:MSHelp=http://msdn.microsoft.com/msHelp>
<HEAD>
<TITLE>oncontextmenu Event Sample</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=iso-8859-1">
<META NAME="AUTHOR" CONTENT="InetSDK">
<META NAME="MS.LOCALE" CONTENT="EN-US">
<META NAME="ROBOTS" CONTENT="noindex">
<!--设置菜单的背景样式-->
<STYLE>
.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}
</STYLE>
<SCRIPT>
<!--弹出菜单:-->
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时背景变为黄色
}
}
</SCRIPT>
<!-- SAMPLE_STYLE_START -->
<LINK REL="stylesheet" HREF="/workshop/basicSDKIE4.css" TYPE="text/css">
<!-- SAMPLE_STYLE_END -->
<LINK REL="stylesheet" TYPE="text/css" HREF="ms-help://Hx/HxRuntime/HxLink.css"><STYLE TYPE="text/css">
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: ;}
</STYLE>
</HEAD>
<!-- TOOLBAR_START -->
<!-- TOOLBAR_EXEMPT -->
<!--TOOLBAR_END-->
<BODY TOPMARGIN=0 LEFTMARGIN=0 BGPROPERTIES="FIXED" BGCOLOR="#FFFFFF"
LINK="#000000" VLINK="#808080" ALINK="#000000">
<BLOCKQUOTE CLASS="body">
<!-- CONTENTS_START -->
<H1>oncontextmenu Event Sample</H1>
<P>This sample shows how to use the <B>oncontextmenu</B> 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.
</P>
<SPAN class="clickableSpan">
1. The default context menu always displays when you right-click in this box.
<b><br>Code: </b>
//no code necessary
</SPAN><br><br>
<SPAN class="clickableSpan" oncontextmenu="return event.ctrlKey">
2. 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.
<b><br>Code: </b>
oncontextmenu="return event.ctrlKey"
</SPAN><br><br>
<SPAN class="clickableSpan" oncontextmenu="return false">
3. A context menu never displays when you right-click in this box.
<b><br>Code: </b>
oncontextmenu="return false"
</SPAN><br><br>
<SPAN class="clickableSpan" oncontextmenu="displayMenu();return false">
4. A custom context menu displays when you right-click in this box.
<b><br>Code: </b>
oncontextmenu="showMenu();return false;"
</SPAN><br><br>
<SPAN class="clickableSpan" oncontextmenu="if (!event.ctrlKey){displayMenu();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.
<b><br>Code: </b>
oncontextmenu="if (!event.ctrlKey){displayMenu();return false;}"
</SPAN><br>
<div id=menu1 onclick="clickMenu()" onmouseover="switchMenu()" onmouseout="switchMenu()" style="position:absolute;display:none;width:100;background-Color:menu; border: outset 3px gray">
<div class="menuItem" id=mnuRed>Red</div>
<div class="menuItem" id=mnuGreen>Green</div>
<div class="menuItem" id=mnuBlue>Blue</div>
<div class="menuItem" id=mnuYellow>Yellow</div>
</div>
<!-- CONTENTS_END -->
<!-- START_PAGE_FOOTER -->
<BR><BR><BR>
<MSHelp:link xmlns:MSHelp="http://msdn.microsoft.com/mshelp" keywords="msdn_copyright" TABINDEX="0">© 2003 Microsoft Corporation. All rights reserved.</MSHelp:link>.
<!-- END_PAGE_FOOTER -->
</BLOCKQUOTE>
</BODY>
</HTML>
<HTML xmlns:MSHelp=http://msdn.microsoft.com/msHelp>
<HEAD>
<TITLE>oncontextmenu Event Sample</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=iso-8859-1">
<META NAME="AUTHOR" CONTENT="InetSDK">
<META NAME="MS.LOCALE" CONTENT="EN-US">
<META NAME="ROBOTS" CONTENT="noindex">
<!--设置菜单的背景样式-->
<STYLE>
.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}
</STYLE>
<SCRIPT>
<!--弹出菜单:-->
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时背景变为黄色
}
}
</SCRIPT>
<!-- SAMPLE_STYLE_START -->
<LINK REL="stylesheet" HREF="/workshop/basicSDKIE4.css" TYPE="text/css">
<!-- SAMPLE_STYLE_END -->
<LINK REL="stylesheet" TYPE="text/css" HREF="ms-help://Hx/HxRuntime/HxLink.css"><STYLE TYPE="text/css">
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: ;}
</STYLE>
</HEAD>
<!-- TOOLBAR_START -->
<!-- TOOLBAR_EXEMPT -->
<!--TOOLBAR_END-->
<BODY TOPMARGIN=0 LEFTMARGIN=0 BGPROPERTIES="FIXED" BGCOLOR="#FFFFFF"
LINK="#000000" VLINK="#808080" ALINK="#000000">
<BLOCKQUOTE CLASS="body">
<!-- CONTENTS_START -->
<H1>oncontextmenu Event Sample</H1>
<P>This sample shows how to use the <B>oncontextmenu</B> 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.
</P>
<SPAN class="clickableSpan">
1. The default context menu always displays when you right-click in this box.
<b><br>Code: </b>
//no code necessary
</SPAN><br><br>
<SPAN class="clickableSpan" oncontextmenu="return event.ctrlKey">
2. 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.
<b><br>Code: </b>
oncontextmenu="return event.ctrlKey"
</SPAN><br><br>
<SPAN class="clickableSpan" oncontextmenu="return false">
3. A context menu never displays when you right-click in this box.
<b><br>Code: </b>
oncontextmenu="return false"
</SPAN><br><br>
<SPAN class="clickableSpan" oncontextmenu="displayMenu();return false">
4. A custom context menu displays when you right-click in this box.
<b><br>Code: </b>
oncontextmenu="showMenu();return false;"
</SPAN><br><br>
<SPAN class="clickableSpan" oncontextmenu="if (!event.ctrlKey){displayMenu();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.
<b><br>Code: </b>
oncontextmenu="if (!event.ctrlKey){displayMenu();return false;}"
</SPAN><br>
<div id=menu1 onclick="clickMenu()" onmouseover="switchMenu()" onmouseout="switchMenu()" style="position:absolute;display:none;width:100;background-Color:menu; border: outset 3px gray">
<div class="menuItem" id=mnuRed>Red</div>
<div class="menuItem" id=mnuGreen>Green</div>
<div class="menuItem" id=mnuBlue>Blue</div>
<div class="menuItem" id=mnuYellow>Yellow</div>
</div>
<!-- CONTENTS_END -->
<!-- START_PAGE_FOOTER -->
<BR><BR><BR>
<MSHelp:link xmlns:MSHelp="http://msdn.microsoft.com/mshelp" keywords="msdn_copyright" TABINDEX="0">© 2003 Microsoft Corporation. All rights reserved.</MSHelp:link>.
<!-- END_PAGE_FOOTER -->
</BLOCKQUOTE>
</BODY>
</HTML>
相关文章推荐
- javascript鼠标事件【部分】
- javascript实现禁止鼠标滚轮事件
- javascript事件列表大全解说,点击事件,双击事件,触发事件,键盘事件,鼠标移动事件,javaScript事件使用小全
- JavaScript事件类型中焦点、鼠标和滚轮事件详解
- JavaScript事件类型中焦点、鼠标和滚轮事件详解
- JavaScript中通过鼠标事件实现模拟拖放效果
- javascript鼠标滚动事件中出现的问题
- javascript滚动栏响应鼠标滑轮的实现上下滚动事件
- javascript 鼠标 触发此事件
- javascript键盘鼠标事件及音频视频图片标签
- 浏览器环境下用javascript创建鼠标点击事件,事件模拟
- 使用Javascript封装实现屏蔽鼠标右键系统键菜单,并绑定自定义的事件
- JavaScript 鼠标经过事件--显示帮助
- JavaScript FAQ(十四)——鼠标事件(一)
- javascript:用脚本模拟鼠标事件
- javascript 鼠标点击事件
- JavaScript中的鼠标滚轮事件详解
- 表格的鼠标事件以及JavaScript动态修改DOM
- JavaScript鼠标事件3
- Javascript鼠标事件