代码示例:
<html > <head > <title >js 事件机制1</title> <meta charset="utf-8" /> <script type="text/javascript"> /*单机事件*/ function testOnclick(){ alert("单机事件"); } function testDblclick() { alert("双击事件"); } /*鼠标事件*/ function testOnmouseover(){ alert("鼠标悬停事件"); } function testOnmousemove(){ alert("鼠标移动事件"); } function testOnmouseout(){ alert("鼠标移出事件") } function testOnmouseenter(){ alert("鼠标移进事件") } /*键盘事件*/ function testOnkeyup() { alert("键盘弹起事件"); } function testOnkeydown() { alert("键盘下压事件"); } /*焦点事件*/ function testOnfocus() { alert("获取焦点"); } function testOnblur(){ alert("失去焦点"); } /*页面加载事件*/ function testOnload() { alert("页面加载"); } testOnload(); /*测试*/ function test() { alert("测试"); } /*改变事件*/ function t1() { alert("改变1"); } </script> <style type="text/css"> #showdiv{ width:300px; height:300px; border:solid 1px red; } </style> </head> <body onload="testOnload()" > <input type="button" value="测试单击" onclick="testOnclick();test()" /> <input type="button" value="测试双击" ondblclick="testDblclick()" /> <div id="showdiv" onmouseover="testOnmouseover()" onmousemove="testOnmousemove()" onmouseout="testOnmouseout()" onmouseenter="testOnmouseenter()" > </div> <input type="text" name="" id="" onkeyup="testOnkeyup()" /> <input type="text" onkeydown="testOnkeydown()"/> <br /> <input type="text" onfocus="testOnfocus()" /> <input type="text" onblur="testOnblur()" /> <select name="" id="" onchange="t1()"> <option value="">北京</option> <option value="">上海</option> <option value="">广州</option> </select> </body> </html>