本文介绍了按钮单击事件是在使用jQuery keypress后触发的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这些代码
$('#search-button').keypress(function (e) {
if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
search();
};
});
$('#search-button').bind('click', function () {
search();
});
我有一个警报,现在每当我按下按钮时焦点,在click事件下的search()也会触发。请帮忙。感谢。
under the search module I have an alert, now whenever I press Enter when the button is in focus, the search() under the click event also triggers. Please help. Thanks.
推荐答案
按Enter键会触发按键事件,但也会触发按钮的点击事件,
Pressing enter does fire the keypress event - but also triggers the button's 'click' event, so you get search called twice.
您不需要为输入键添加处理程序。
You don't need to add a handler for the enter key.
这篇关于按钮单击事件是在使用jQuery keypress后触发的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!