[英]How to press a button with Enter Key
How to bind click(from Button1's click event) event in textbox When I pressed the enter key当我按下回车键时,如何在文本框中绑定点击(来自 Button1 的点击事件)事件
$('#idoftextbox').keypress(function (e) {
var code = e.keyCode || e.which;
if (code === 13) {
//enter has been pressed
};
});
<input type="text" name="textbox" id="textbox" />
$("#textbox").bind('keypress', function(e)
{
if(e.which == 13)
{
// enter key was hit, do what you need to do here
}
});
Since you didn't say what "textbox" means to you (as it can be textarea too), I assumed some dummy markup that I posted and then I bound the event to it.由于您没有说“文本框”对您意味着什么(因为它也可以是 textarea),所以我假设我发布了一些虚拟标记,然后将事件绑定到它。 I don't see the reason for binding an event to click and then bind event after that to the element.
我看不到将事件绑定到单击然后将事件绑定到元素的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.