[英]How to press a button with 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
}
});
由於您沒有說“文本框”對您意味着什么(因為它也可以是 textarea),所以我假設我發布了一些虛擬標記,然后將事件綁定到它。 我看不到將事件綁定到單擊然后將事件綁定到元素的原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.