jQuery UI autocomplete combobox - prevent form submit

匆匆过客 提交于 2019-12-08 12:24:57

问题


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)


回答1:


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>&nbsp;</button>") 

to

$("<button type=\"button\">&nbsp;</button>")

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



来源:https://stackoverflow.com/questions/3794688/jquery-ui-autocomplete-combobox-prevent-form-submit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!