xiongfeng 2011-05-17
代码如下:
<!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> <title>火狐和IE都支持的enter事件</title> <script src="jquery.1.3.2.js" type="text/javascript" language="javascript"></script> <script type="text/javascript"> document.onkeydown = function (e) { var theEvent = window.event || e; var code = theEvent.keyCode || theEvent.which; if (code == 13) { $("#but1").click(); } } $(document).ready(function () { $("#but1").click(function () { alert("我是enter事件," + "text值:" + $("#text1").val()); }) $("#but2").click(function () { alert("我是Jquery事件" + "text值:" + $("#text1").val()); }) }); </script> </head> <body> <input type="text" id="text1" /> <input type="button" id="but1" value="确定(我是enter事件)"/> <input type="submit" id="but2" value="确定(我是Jquery事件)" /> </body> </html>