jquery.autocomplete插件如何禁用?

在使用jquery.autocomplete的时候,我们有时候需要在运行的时候关闭自动完成的功能,jquery.autocomplete好像不提供关闭的方法,在网上找了一下,发现有一个解决方案,原文是英文的,简单翻译一下。

解决的方法是这样的:

  1. 自儿个改代码
  2. 将minChars设置成一个非常大的数字,例如999999,其实只要设置为input的maxlength + 1就可以了,因为用户永远也输入不了这么多的数字(我觉得这个方法是最好的,非常实用,很巧的方法)
  3. 用jquery.remove()方法移掉当前的input,并且添加一个新的input
  4. 使用两个input,交替显示隐藏

我还是觉得最第二个方法是最好的方法,其它还可以设置delay为一个相当大的数字,不过不如minChars好,因为delay应该是使用一个setTimeout或者setInteval之类的函数,时间久了,还是会弹出来的

原文如下:

>Hi, I'm using the autocomplete plugin, the one that is modification of
>Dylan Verheul's jQuery Autcomplete plug-in.
>It's working great but I need to disable it using any function, and I
>don't know how to do it.
>
>I've tried with unbind() ?¿ on the field but it's not working :(
>
>Any help?

Not sure which MOD you're using (there are several) but if your using the
one I wrote (located at Pengoworks.com) then there is no way to disable the
behavior in the current code base.

Some possible workarounds:

1) MOD the code to add this feature.

2) Move to the latest more official version at
http://dev.jquery.com/browser/trunk/plugins/autocomplete. This doesn't have
a disable feature yet, but you could use the setOptions() method and set the
minChars to a really high number (like 999999.) This code is heavily
refactored so you would need to re-write your current code.

3) Use the jQuery .remove() method to complete remove the input and replace
it with a new field.

4) Use 2 input elements in your form--one that has the autocomplete behavior
attached and one that does not. You can then hide/show the appropriate
fields. They should each have unique IDs, but the could have the same name.
As long as the hidden field's value is blank, you'll get the value from the
visible element.

-Dan

  

注意:本文为我的独立博客镜像博客,自发表不再更新,原文可能随时被更新,敬请访问原文。同时,请大家不要在此评论,如果有什么看法,请点击这里:http://iove.net/1705/

本文来自http://iove.net,欢迎转载,转载敬请保留相关链接,否则视为侵权,原文链接:http://iove.net/1705/

转载于:https://www.cnblogs.com/conis/archive/2009/12/05/1720441.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值