<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>以上这段代码按回车没反应,改成<body onkeydown = "gg()">就有了,就是把onkeydown放在body里。
之前那样调用为啥不行,不也是body里吗?求大神解释。
<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>以上这段代码按回车没反应,改成<body onkeydown = "gg()">就有了,就是把onkeydown放在body里。
之前那样调用为啥不行,不也是body里吗?求大神解释。
解决方案 »
- 谁能帮我写个javascript 小程序,进来看看就知道了,小弟跪谢啦。
- 基本数据类型的问题 求助
- JS里有没有调用OpenFileDialog的方法
- 复选框问题。
- 用正则工具测试 "\/" 可以匹配 "/" ,这是为什么?
- 关于this指针的疑问。
- this.superclass.constructor.apply(this,arguments) 具体是什么意思啊?请给于帮助了啊
- 复选框在本页传值问题,急急,在线等!
- EXT 4.0加载远程json数据 为什么加载不了呢?
- 求助大家帮忙写一段JS代码
- 如何在ExtJS的toolbar按钮按下时生成一个小窗口
- 三天两夜纠结在这简单extjs问题上,程序员妹纸求救ing
那我为啥加了document.getElementById("start").focus(); 还是不行呢。
var values = encodeURIComponent(encodeURIComponent($(this).val())); window.location = PostURL + value; //window.location = PostURL + "?Keywords=" + values; return false;
} }); $(QueryObj).parent().siblings().find("input").click(function () {
var value = $(QueryObj).val();
var values = encodeURIComponent(encodeURIComponent($(QueryObj).val()));
window.location = PostURL + value; //window.location = PostURL + "?Keywords=" + values; });
if (event.keyCode == 13) {
var value = $(this).val();
var values = encodeURIComponent(encodeURIComponent($(this).val()));
window.location = PostURL + value;
//window.location = PostURL + "?Keywords=" + values;
return false;
}
});
$(QueryObj).parent().siblings().find("input").click(function () {
var value = $(QueryObj).val();
var values = encodeURIComponent(encodeURIComponent($(QueryObj).val()));
window.location = PostURL + value;
//window.location = PostURL + "?Keywords=" + values;
});QueryObj 就是你的控件对象 如你的 $("#start") 就是 $() 别忘了调用 Jquery
<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>
<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>