-1

我的 jQuery Autocomplete 在 jQuery 版本 1.9 上运行良好,但是当我使用 jQuery v1.8.3 时,它会显示错误:

TypeError: $(...).autocomplete is not a function

由于其他功能也受到干扰,我无法将我的 jQuery 版本从 v1.8.3 更改为 1.9。如何在这个 jQuery v1.8.3 版本中使用 jQuery 自动完成功能?我说的是这个Autocomplete

这是我的代码:

<script src="<?php bloginfo('template_url');?>/library/js/jquery_1.9.js"></script>
<script src="<?php bloginfo('template_url');?>/js/UI/ui/jquery-ui.js"></script>
<link rel="stylesheet" href="<?php bloginfo('template_url');?>/js/UI/themes/base/jquery-ui.css">


function autoComplete(obj)
{
    var term_val = obj.value
    var findin   = "";
    if(term_val == "")
    {
        console.log(term_val);
        $("#"+obj.id).val("");
        $("#ui-id-1").remove();
    }
    else
    {
        $.ajax({
              type:"POST",
              url:"<?php echo bloginfo('template_url')?>/ajax.php", data:"&term_val=" + term_val,
              dataType:"json",
              success:function (data) {
              var availableTags = data;

                  $( "#"+obj.id ).autocomplete({
                      minLength: 0,
                      source: availableTags
                  });
              }
          });


    }

}


<input type="text" name = "quick_search_new" id="quick_search_new" onkeyup="autoComplete(this)" autocomplete="off"/>

当我将上述 jQuery 文件与 1.8 版本一起使用时,它无法正常工作,显示错误:

<script src="<?php bloginfo('template_url');?>/library/js/jquery_1.8.js"></script>
    <script src="<?php bloginfo('template_url');?>/js/UI/ui/jquery-ui.js"></script>
    <link rel="stylesheet" href="<?php bloginfo('template_url');?>/js/UI/themes/base/jquery-ui.css">
4

1 回答 1

0

我通过将我的 Jquery Ui 版本从 jQuery UI - v1.10 更改为 jQuery UI - v1.8.24 来解决我的问题。它工作正常。谢谢大家

<script src="<?php bloginfo('template_url');?>/js/UI/ui/jquery-ui.js"></script> <!-- Version  v1.10 -->

替换为

<script src="<?php bloginfo('template_url');?>/js/UI/ui/jquery-ui.js"></script> <!-- Version  v1.8.24 -->

现在它工作正常。

于 2013-12-29T12:00:40.083 回答