日期:2014-05-16 浏览次数:20402 次
<html>
<head>
<script type="text/javascript">
function gg() //整个页面如果有回车键事件发生时
{
if(event.keyCode==13)
{
document.getElementById("start").click();
return false;
}
}
</script>
</head>
<body>
<form>
<input type="button" id = "start" onclick = "alert('sb')" value="调用函数" onkeydown = "gg()">
</form>
</body>
</html>
<html>
<head>
<script type="text/javascript">
(function()
{
if(event.keyCode==13)
{
document.getElementById("start").click();
return false;
}
})()
</script>
</head>
<body>
<form>
<input type="button" id = "start" onclick = "alert('是这样的,匿名 函数 闭包执行')" value="调用函数" >
</form>
</body>
</html>
<body>
<input type="button" id = "start" value="回车试试" onkeydown = "gg(event)">
<script type="text/javascript">
window.onload=function(){
document.getElementById("start").focus();//自动获取焦点
};
function gg(e){
e = e
------解决方案--------------------
event;
var code = e.which
------解决方案--------------------
e.keyCode;
if (code == 13
------解决方案--------------------
code == 32){
alert("鼠标在id:start 并且你按了回车!");
}
}
</script>
</body>