在 firefox 抓不到 window.event,所以要用以下的 function 來處理 keyCode:
<!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> new document </title>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<script language="javascript">
function myKeyPress(evt){
evt = (evt) ? evt : ((window.event) ? window.event : "") //兼容IE和Firefox获得keyBoardEvent对象
var key = evt.keyCode?evt.keyCode:evt.which; //兼容IE和Firefox获得keyBoardEvent对象的键值
if(evt.ctrlKey && (key == 13 || key == 10)){
alert("send");//同时按下了Ctrl和回车键
}
}
</script>
</head>
<body onkeypress="myKeyPress(event)">
</body>
</html>
參考: http://www.felix021.com/blog/read.php?1171