87,991
社区成员
发帖
与我相关
我的任务
分享<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>
<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>
<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>
$(QueryObj).keydown(function (event) {
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
$(QueryObj).keydown(function (event) {
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;
});