将回车键绑定到页面上的特定按钮 [英] Bind enter key to specific button on page

查看:117
本文介绍了将回车键绑定到页面上的特定按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<input type="button" id="save_post" class="button" value="Post" style="cursor:pointer;"/>

如何将人员键盘上的回车键绑定到页面上的此特定按钮?这不是一种形式,我也不希望它是。

How can I bind the enter key on the persons keyboard to this specific button on the page? It's not in a form, and nor do I want it to be.

谢谢!

推荐答案

This will click the button regardless of where the "Enter" happens on the page:

文件).keypress(函数(e){
if(e.which == 13){
$(#save_post)。click();
}
} );

$(document).keypress(function(e){ if (e.which == 13){ $("#save_post").click(); } });

这篇关于将回车键绑定到页面上的特定按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆