JQuery 的 ajaxForm 在点击时提交,但在空间上不提交
JQuery 众所周知且深受喜爱的插件 ajaxForm 修改ajax提交的表单。
我已经让它正常工作,包括回调函数。我发现问题在于,在很多情况下,我不是按 Enter 键,而是按 tab space
组合。这在填写文本区域时很有用,或者只是因为它比使用鼠标更快。
在我的实现中,单击“提交”按钮可以按预期工作,但单击“制表符”、“空格” - 不会执行任何操作。表单未提交,页面未刷新。
我不知道是什么原因导致这个问题,或者我将如何调试它。请帮忙:)
浏览器信息:
Ubuntu 10.04
FireFox 3.6.18 失败
google-chrome 12.0.742.112 失败
Windows 7
Firefox 3.6.15 失败
Chrome 12.0.742.112 失败
Internet Explorer 9.0.8080.16413 - 按预期工作。
JQuery's well known and loved plugin ajaxForm modifies the form to be submitted by ajax.
I've gotten this to work correctly, including callback functions. What I found broken is that in many cases instead of hitting enter, I hit tab space
combination. This is useful in cases of filling out textareas, or just because it's faster than reaching for the mouse.
In my implementation clicking the submit button works as expected, but hitting tab, space - does nothing. Form doesn't submit, page doesn't refresh.
I don't know what causes this, or how I would go about debugging it. Please help :)
Browser Info:
Ubuntu 10.04
FireFox 3.6.18 fails
google-chrome 12.0.742.112 fails
Windows 7
Firefox 3.6.15 fails
Chrome 12.0.742.112 fails
Internet Explorer 9.0.8080.16413 - works as expected.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我能想到的两个可能的原因是:
ajaxSubmit
和ajaxForm
。对于2,您可以使用 FF 插件 FireQuery 进行直观检查。
对于 1,您可能需要单步执行插件的实际代码,即
jquery.form.js
。取决于您使用的表格方法; ifajaxSubmit
,在第 290 行附近设置断点 (doSubmit
); ifajaxForm
,大约第 589 和 594 行。我希望这可以帮助您调试错误。
如果您发现这是第一种情况,您可能需要为按钮附加一个按键处理程序并在浏览器中模拟相同的行为:
Two possible causes that I can think of are:
ajaxSubmit
andajaxForm
on the same form.For 2, you can visually check with FireQuery, a plugin for FF.
For 1, you may need to step into the actually code of the plugin, i.e.
jquery.form.js
. Depending which method you use for the form; ifajaxSubmit
, set a breakpoint around line 290 (doSubmit
); ifajaxForm
, around line 589 and 594.I hope that helps you in debugging the error.
If you found out it is the first case, you may need to attach a keypress handler for the button and simulate the same behaviour across browsers:
尝试将您自己的点击处理程序添加到提交按钮,并放入测试警报以查看是否会触发。
如果有效,您可以自己在表单上调用“提交”。
Try adding your own click handler to the submit button and put in a test alert to see if that fires.
If that works you could call submit on the form yourself.
AFAIK,GTK+ 不会触发空格键上的点击。此外,空格键通常与页面滚动相关(大多数浏览器),因此默认情况下它可能不会触发单击。
一种修复方法是在文档上绑定
按键
,并手动触发点击
或表单提交
。请注意,我使用命名空间事件来避免与表单上的任何其他
keypress
事件处理程序发生任何冲突。AFAIK, GTK+ doesn't trigger click on spacebar. Also, spacebar is usually tied to page scroll (by most broswers) so it may not trigger a click by default.
One fix is to bind a
keypress
on the document and manually trigger aclick
or formsubmit
.Note that I'm using namespaced event to avoid any conflicts with any other
keypress
event handler on the form.