我在我的项目中添加了一个新的js库(typeahead.bundle.js),每当我尝试调用它声称它们不存在的任何函数时。它似乎在寻找jQuery而不是我的库:
Uncaught TypeError: $(...).typeahead is not a function
(anonymous function) @ Create:50
x.Callbacks.c @ jquery-1.10.2.min.js:21
x.Callbacks.p.fireWith @ jquery-1.10.2.min.js:21
x.extend.ready @ jquery-1.10.2.min.js:21q @ jquery-1.10.2.min.js:21
我也用jQuery-ui找到了这个问题。
相关用法:
<script src="/Scripts/typeahead.bundle.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$( "#MemberSearch" ).typeahead({ //error line
source: function (request, response) {
$.ajax({
url: "/Operations/AutoCompleteMember",
type: "POST",
dataType: "json",
data: { term: request.term },
success: function (data) {
response($.map(data, function (item) {
return { label: item.Member, value: item.Member };
}))
}
})
},
messages: {
noResults: "", results: ""
}
});
})
</script>
...
<div class="form-group">
@Html.Label("Member Search", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBox("MemberSearch", "", htmlAttributes: new { @class = "form-control btn-group" })
<button type="button" onclick="" class="btn btn-group" aria-label="Left Align">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
</button>
</div>
</div>
答案 0 :(得分:0)
尝试安装typeahead nuget package,在包含jquery之后添加指向脚本<script src="~/Scripts/bootstrap3-typeahead.js"></script>
的链接,然后就可以了