jQuery UI 自动完成组合框 - 防止表单提交

发布于 2024-09-24 14:24:21 字数 762 浏览 0 评论 0原文

我正在使用 jQuery UI 自动完成的漂亮“组合框”变体 - 请参阅此处: http://jqueryui .com/demos/autocomplete/#combobox

我将它放在 Form 元素中,因为它是表单的一部分。

自动完成组合框有一个

我如何阻止它提交?

(注意:这个人也有同样的问题,但他解决了通过删除 form 来实现 - 我不能这样做)

I'm using the nifty 'combobox' variant of jQuery UI Autocomplete - see here: http://jqueryui.com/demos/autocomplete/#combobox

I have it within a Form element because its part of a form.

The Autocomplete Combobox has a <button> that is used to show the whole drop down list. However when the user presses it, the form submits. This appears to be because the <button> has a type="submit" attribute. The whole element is created by the button() call within the .combobox fn, see source code.

How do I stop it submitting?

(NB: This guy had the same problem but he fixed it by removing the form - I can't do that)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兔姬 2024-10-01 14:24:21

啊,没关系,我已经弄清楚了。

该问题在 jQuery 论坛上进行了讨论:
http://forum .jquery.com/topic/autocomplete-combobox-problem-when-it-is-placed-inside-a-form-tag

他们建议了几种不同的方法来调整自动完成组合的源代码来修复它。最简单的似乎是这样的:

$("<button> </button>") 

更改这

$("<button type=\"button\"> </button>")

可以防止将 type="submit" 插入到最终按钮中。

Ah, nevermind, I figured it out.

The problem is discussed on the jQuery forum here:
http://forum.jquery.com/topic/autocomplete-combobox-problem-when-it-is-placed-inside-a-form-tag

They suggest several different ways of adjusting the source code of the autocomplete combo to fix it. The simplest one seems to be this:

Change the line that says

$("<button> </button>") 

to

$("<button type=\"button\"> </button>")

this prevents the type="submit" from being inserted into the final button.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文