?Briella 2015-08-27 11:18 采纳率: 0%
浏览 32

销毁jQuery自动完成

I'm using Autocomplete jQuery UI in one my project and I want to destroy autocomplete in one case.

I have a web page where there are 2 fields i.e Country and Ext No. Where user choose a country I'm triggering an ajax call to get all ext no for that country. If there are any ext no available for that country then I have set the autocomplete list on Ext No field. So where ext no is exist for a country then I'm able to set new autocomplete list on the Ext No field. But there are some countries which don't have any ext no, so in that case I want to destroy autocomplete list on Ext No field.

Below is the code I'm using to destroy autocomplete on Ext No field.

if ($('#ext_no').data('autocomplete')) {
  $('#ext_no').autocomplete("destroy");
}

But this is not working. I'm always getting $('#ext_no').data('autocomplete') as undefined. For the very first time it was undefined that's fine but when user choose a country for next time it should not return undefined.

Let me know if anyone has any idea what I'm doing wrong here or is there any other way to destroy autocomplete for field if it was set on that field.

  • 写回答

2条回答 默认 最新

  • 关注

    I think in the newer versions of jQuery UI, the data property name is changed to uiAutocomplete not autocomplete So

    if ($('#ext_no').data('uiAutocomplete')) {
      $('#ext_no').autocomplete("destroy");
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题