【问题标题】:How to initialize after: Error: cannot call methods on autocomplete prior to initialization之后如何初始化:错误:无法在初始化之前调用自动完成的方法
【发布时间】:2016-12-15 15:40:25
【问题描述】:

我之前有一个旧的自动完成脚本在输入表单上运行旧的 jQuery。我想将 markItUp 添加到我的文本输入表单中,而我使用的自动完成版本不再适用于较新的 jQuery。

我看到 jquery-ui.js 中提供了最新的自动完成功能,但安装后我开始收到以下警告:

错误:无法在初始化之前调用自动完成的方法; 试图调用方法'/include/suggest.php'

我查了初始化并在$(document).ready(function()之后添加了这个:

$(this.target).find('input').autocomplete();

同样的错误信息。因此,我尝试使其更具体到正在自动完成的输入字段:

$(this.target).find("input[id^='last_']").autocomplete();

我在这里有点失明。这个页面的自动完成功能是由我不再有权访问的人完成的,而且我自己从来没有真正写过 jQuery 的东西。我试图理解这一点,但现在我很困惑。

这是页面的骨架:

<script src="/jquery/1.9.1/jquery.min.js"></script>
<link rel="stylesheet" href="/inc/auto/main.css" type="text/css" />
<link rel="stylesheet" href="ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="/js/markitup/jquery.markitup.js"></script>
<script src="/js/markitup/sets/default/set.js"></script>

    [markitup styles]

<script>
  function html_entity_decode(str)
  {
    var ta=document.createElement("textarea");
    ta.innerHTML=str.replace(/</g,"&lt;").replace(/>/g,"&gt;");
    return ta.value;
  }
    $(document).ready(function() {
  $("#markItUp").markItUp(mySettings);

    $(this.target).find('input').autocomplete();
    $("input[id^='last_']").autocomplete('/include/suggest.php',{
            matchCase:true,
            formatItem: function(data, i, total)
            {
                var s=data[0].split(",")
                return s.join(" "); 
            }
    });

    $("input[id^='last_']").result(function(event, data, formatted){

        var ids=this.id.split('_')
        var id=ids[1]; // from last_xx got xxx

        var s=html_entity_decode(data[0]).split(",");

        $(this).next().focus();
        $(this).next().select();

        //have only last value -- TAB pressed
        if(s.length==1)return;

        $('#first_'+id).val(s[0]);
        $('#middle_'+id).val(s[1]);
        $('#last_'+id).val(s[2]);
    });

       });
</script>
</head>
<body>
<h1>News Inserter</h1>
<form action="/forms/cronkite.shtml"  accept-charset="UTF-8" method="POST">

Reporter (Last, First Middle):<br />
<input type="text" id="last_1" name="lastreporters" size="15" maxlength="30" value="" />, <input type="text" id="first_1"     name="firstreporters" size="15" maxlength="30" value="" /><input type="text" id="middle_1" name="middlereporters" size="15" maxlength="30" value="" /><br />
Story:<br />
[markitup text area]
<input type="SUBMIT" value="Insert Data" /><input type="RESET" value="Reset" /><br />
</form>

问题仅在我的初始化调用中吗?另外一点:我使用的自动完成版本是 Autocomplete - jQuery plugin 1.1pre 版权所有 2007。自动完成的 jQuery-ui 版本是否发生了足够的变化,以至于我需要更新我的表单?

【问题讨论】:

    标签: javascript jquery jquery-ui autocomplete


    【解决方案1】:

    由于旧版本的 Jquery,我遇到了同样的问题,然后我添加了“http://code.jquery.com/jquery-migrate-1.0.0.js”Js 现在一切正常。

    【讨论】:

      【解决方案2】:

      在浏览了教程之后,我发现 jquery-ui 已经发生了很大的变化。继续学习教程!

      【讨论】:

        猜你喜欢
        • 2014-02-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-11-08
        • 1970-01-01
        • 1970-01-01
        • 2013-02-26
        • 1970-01-01
        相关资源
        最近更新 更多