2
我正在使用jQuery,并且在common.js中有这段代码文件。
此代码在用户按下进入页面任意位置时触发submit
或next
按钮。
我使用的Cancel
和Submit
按键,分别是.btn
类和所有Next
按键两种不同的CSS类使用.back
类。
此代码适用于Internet Explorer,FireFox和Chrome。只有Safari让我很难过。当用户关注Cancel
,然后按Enter
它提交表单而不是取消它。
有没有人有解决方案?我尝试了很多东西,但没有任何作用。
如果您有针对所有浏览器的Safari特定解决方案或解决方案,请让我知道,因为现在我无法更改我的JSP代码。
预先感谢您。
// Common.js
$("form *").live('keypress', function (e) {
if ($(this).parents('form').find('button[type=submit].btn, input
type=submit].btn').length <= 0) {
return true;
}
if ($(this).parents('form').find('textarea').is(":focus")) {
alert(' Function Call ');
return true;
} * * *
if ($(this).parents('form').find('.back').is(":focus")) {
return true;
} * * *
if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
$(this).parents('form').find('button[type=submit].btn, input
[type=submit].btn').click();
return false;
}
});
// test.jsp
<div class="back-link">
<div class="back-btn-wrap">
<html:cancel styleClass="back" onclick="bCancel=true">cancel</html:cancel>
</div>
<div class="btn-wrap">
<html:submit styleClass="btn" property="submitNext"> Submit/Next</html:submit>
</div>
</div>
http://jsbeautifier.org/,去吧! – Alexander
你使用的是什么版本的jQuery? :从1.6开始,重点似乎已经实现到了核心中,但它并不在新的API中。 –
我一直在使用'$(elm).is(':focus')'并且我的主浏览器Safari从来没有遇到任何问题。在你的场景中,我会确保我的代码中的目标元素是正确的。此外,您可能想切换到'.on()'处理程序,因为'.live()'在jQuery的一些旧版本中已被弃用。 – inhan