将按Enter键与按钮单击jQuery链接 [英] Linking the pressing of Enter to a button click with jQuery
本文介绍了将按Enter键与按钮单击jQuery链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在模态表格上有一些句子:
I have some bottons on a modal form:
<div class="block-footer align-right">
<button type="button">Submit</button>
<button type="button">Submit & Close</button>
<button type="button">Close</button>
</div>
如何让用户点击Enter键然后点击第一个按钮提交被点击。这对于点击操作很重要,因为我希望用户在点击时可视地看到按钮更改的颜色。
How can I make it so the when a user clicks on the Enter key then the first of the buttons "Submit" is "clicked". It's important for the click action as I want the user to visually see the color of the button change as it is clicked.
请注意,我已经执行了以下操作并将其绑定执行该按钮的函数:
Note that I already did the following and tied the execution of a function to that button:
$('#modal button:contains("Submit")').click(function () {
submitHandler(dObj.$link, $('#main-form'), false);
});
推荐答案
这将检测到'Enter'键按
This will detect 'Enter' key press
$(document).keypress(function(event){
var keycode = (event.keyCode ? event.keyCode : event.which);
if(keycode == '13'){
$('#Submit').click();
}
});
这篇关于将按Enter键与按钮单击jQuery链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文