jquery:阻止表单提交
嘿伙计们, 我有一个可以用向上和向下键影响的表单。
如果没有该代码,它只是一个触发正常操作的正常输入搜索字段。但是我想知道当我使用向上和向下箭头键更改输入字段的值时如何停止默认行为。
看看这个: http://jsfiddle.net/3UHVY/7
我只希望在以下情况下发生警报我使用向上和向下键更改该框的值,否则不应触发任何警报,并且应正常提交表单。但是,如果通过箭头键更改输入值,则应触发警报并且不应提交表单。
知道如何解决这个问题吗?
hey guys,
i have a form that can be influenced with up and down keys.
without that code it's just a normal input-search field that fires a normal action. however i wonder how i can stop the default behaviour when i change the value of the input field with the Up and Down arrow keys.
check out this: http://jsfiddle.net/3UHVY/7
I only want the alert to happen if I change the value of the box with the up and down keys, otherwise no alert should be fired and the form should be submitted normally. However if the input-value is changed via the arrow keys JUST THE ALERT should be fired and the form should not be submitted.
any idea how to solve that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
http://jsfiddle.net/3UHVY/14/
http://jsfiddle.net/3UHVY/14/
我不完全确定你想要发生什么,但是以下 jQuery:
JS Fiddle demo
问题是我不确定您想要在哪里触发提交,尽管我假设您希望在既没有按下向上也没有按下时进行提交,因此它位于 else 中 声明)。
I'm not entirely sure what you want to happen, but the following jQuery:
JS Fiddle demo
The problem is that I'm not sure where you want to trigger the submit, though I've assumed you want submission to occur if neither up nor down is pressed, hence it's in the
else
statement).几点说明:
事件)按上/下键后,
停止默认的向上/向下行为
(自动完成建议)
当用户输入不同的内容时
比向上/向下,所以形式是“新鲜的”,
按下时提交表单的代码
输入 (13)
Few notes:
event) after pressing up/down, to
stop default up/down behavior
(autocomplete suggestions)
when user inputs something different
than up/down, so the form is "fresh"
code to submit the form when pressing
enter (13)