输入触发表单提交 [英] Enter fires the form submit
问题描述
我有一个div(好的gif,如果它是一个按钮),在该div上是一段javascript,它处理ENTER,如果它是一个点击($(this).click())。点击有自己的功能。
I have a div (nice gif dislayed as-if it's a button), on that div is a piece of javascript that handles the ENTER as-if it's a click ($(this).click()). The click does its own thing.
在FireFox中,一切运行完美:用户按下按钮上的Enter键并点击。
在IE中,提交的表单不是点击()
In FireFox, it all works perfectly: the user presses the enter on the button and the click is fired. In IE, the form is submitted not the click()
HELP !!
推荐答案
这是一个方便的花花公子jQuery函数,我用它来解决这个问题。
this is a handy dandy jQuery function i use to get around this.
$(formSelector).find('input, select').keypress(function (event) {
if (event.keyCode == 13) {
event.preventDefault();
$(buttonSelector).click().focus();
return false;
}
});
formselector只是一个持有'#FormId'的变量,而buttonSelector是一个持有按钮i的变量想要点击。所以在你的情况下它会是:'#IdOfYourDivToClick'。
formselector is just a variable holding the '#FormId', and buttonSelector is a variable holding the button i want clicked. so in your case it would be: '#IdOfYourDivToClick'.
这篇关于输入触发表单提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!