自动完成“不是一个功能” [英] autocomplete "is not a function"
问题描述
我们在一个简单的HTML页面中测试了Jquery UI(jquery-ui-1.8.10.custom.min.js)自动完成功能。
We've tested the Jquery UI (jquery-ui-1.8.10.custom.min.js) Autocomplete function in a simple HTML page which worked.
然后我们将相同的代码复制到Asp.net用户控件中,它就会停止工作。 Javascript错误显示$ searchBox.autocomplete不是函数。
We then copy the same code into an Asp.net User Control and it stops working. The Javascript error reads "$searchBox.autocomplete is not a function".
此用户控件正在Asp.net Sitefinity 3.7项目中使用。在页面上它有一个ScriptManager。不确定我还能添加什么...
This user control is being used in an Asp.net Sitefinity 3.7 project. On the page it has a ScriptManager. Not sure what else I can add...
任何人都知道发生了什么?
Anyone know what's going on?
修改:
<script src="/js/jquery-1.5.min.js" type="text/javascript"></script>
<script src="/js/jquery-ui-1.8.10.custom.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
var termTemplate = "<span class='ui-autocomplete-term'>%s</span>";
$('input#searchInput').autocomplete({
source: ['johannesburg z', 'johannesburg x', 'johannesburg v', 'johannesburg b', 'johannesburg a', 'johannesburg q', 'johannesburg u', 'johannesburg y', 'johannesburg o', 'johannesburg p'],
minLength: 3,
open: function (e, ui) {
var
acData = $(this).data('autocomplete'),
styledTerm = termTemplate.replace('%s', acData.term);
acData
.menu
.element
.find('a')
.each(function () {
var me = $(this);
me.html(me.text().replace(acData.term, styledTerm));
});
}
});
});
</script>
<div class="outerSearchBox">
<div class="searchFieldWrapper">
<input id="searchInput" type="text" class="searchField" /><a class="searchButton">SEARCH
</a>
<div class="searchSugContainer">
谢谢。
推荐答案
该错误通常意味着尚未加载jquery或插件。在加载文档之前检查您的函数调用是否未被命中:
That error usually means that jquery or the plugin hasn't yet been loaded. Check that you're function call isn't getting hit before the document is loaded:
$(function(){
var $searchBox = $('#mysearchBox');
$searchBox.autocomplete(...);
});
同时检查javascript文件的路径是否正确。 Firebug 或Google Chrome开发人员工具可用于检查这两个问题。
Also check that the path to the javascript files are correct. Firebug or google chrome developer tools are useful for checking both of these issues.
这篇关于自动完成“不是一个功能”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!