如何在用户点击提交时使jQuery自动完成执行搜索() [英] How to make jQuery autocomplete execute a search() when user hits submit
问题描述
正如我上一篇文章所介绍的那样 - 如何修剪输入到JQuery自动完成框?。我决定提出一个新问题,而不是继续编辑该问题。
As a follow on my from last post - How would I trim the input to a JQuery auto-complete box? . I decided to make a new question rather than to continue editing that one.
我目前有jQuery ui自动完成1.8(大概)工作得很好,除了一件事。如果用户只输入(有效)名称并点击提交,则自动完成查找将永远不会运行,因此相关值永远不会被绘制并分配给输入框。这当然是一个问题。阅读文档,这意味着我可以使用jQuery search()
方法来克服这个问题。但是,我正在努力实现它的工作。我曾尝试在文本输入的onblur事件以及submit按钮的onclick事件中调用 search()
,但无济于事 - 每当我点击提交我对输入框没有任何价值。代码:
I currently have jQuery ui autocomplete 1.8 (or so) working reasonably well, except from one thing. If the user just enters a (valid) name and hits submit, the auto-complete lookup never runs, and so the associated value is never grapped and assigned to the input box. This, of course, is a problem. Reading the documentation, it implies that I could use the jQuery search()
method to over-come this. However, I am struggling to get it to work. I have tried both putting the call to search()
in the onblur event of the text input, and in the onclick event of the submit button, but to no avail - whenever I hit submit I have no value for the input box. The code:
<form action = "<?php echo $this->URL();?>" method="post">
<fieldset>
<ol>
<li>
<label for="Resource">Resource</label>
<input id="Resource" name="Resource" class="text" type="text" value="" onblur="jQuery('#Resource').search();"/>
</li>
</ol>
</fieldset>
<fieldset class="submit">
<input id="Submit" name="Submit" type="Submit" class="Submit" value ="Submit" onclick = "jQuery('#Resource').search();"/>
</fieldset>
</form>
那么,我到底做错了什么?
So, what exactly am I doing wrong?
推荐答案
您需要在更改事件中添加自动选择任何匹配结果代码。
You need to add the automated-choose-any-matching-result code in the change event.
在您的其他问题上查看我的回答:
jQuery自动填充问题 - 如果用户没有专门选择
Check my answer on your other question: jQuery autocomplete problem - doesn't match if user doesn't specifically select
这篇关于如何在用户点击提交时使jQuery自动完成执行搜索()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!