x=event.clientX y=event.clientY alert("X coords: " + x + ", Y coords: " + y) } </script> </head>
<body onmousedown="show_coords()"> <p>Click in the document. An alert box will alert the x and y coordinates of the cursor.</p> </body>
</html>
按一个键则显示该键的ASCII码
<html> <head> <script type="text/javascript"> function whichButton() { alert(event.keyCode) }
</script> </head>
<body onkeyup="whichButton()"> <p><b>Note:</b> Make sure the right frame has focus when trying this example!</p> <p>Press a key on your keyboard. An alert box will alert the unicode of the key pressed.</p> </body>
</html>
单击任何地方显示鼠标在页面的坐标
<html> <head>
<script type="text/javascript"> function coordinates() { x=event.screenX y=event.screenY alert("X=" + x + " Y=" + y) }
<p> Click somewhere in the document. An alert box will alert the x and y coordinates of the cursor. </p>
</body> </html>
显示SHIFT是否被按下
<html> <head>
<script type="text/javascript"> function isKeyPressed() { if (event.shiftKey==1) { alert("The shift key was pressed!") } else { alert("The shift key was NOT pressed!") } }
<p> Click somewhere in the document. An alert box will tell you if you pressed the shift key or not. </p>
</body> </html>
单击显示我们页中的标签
<html> <head> <script type="text/javascript"> function whichElement() { var tname tname=event.srcElement.tagName alert("You clicked on a " + tname + " element.") } </script> </head>
<body onmousedown="whichElement()"> <p>Click somewhere in the document. An alert box will alert the tag name of the element you clicked on.</p>
<h3>This is a header</h3> <p>This is a paragraph</p> <img border="0" src="http://www.webjx.com/htmldata/sort/ball16.gif" width="29" height="28" alt="Ball"> </body>