所以我正在开发一个MVC 5应用程序,该应用程序是在2014年编写的,并且使用的是旧版本的JQuery,因此一些功能已被弃用,因此,通过使用谷歌Chrome的开发人员工具,通过F12热键,我一直收到这些控制台错误。我根据这两个SO帖子在JQuery library
之前导入了JQuery UI
:
Uncaught TypeError: $(...).autocomplete is not a function和TypeError: $(...).autocomplete is not a function如下所示,但此尝试仍然无法解决问题。
_Layout.cshtml:
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<script src="//cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="@Url.Content("~/Content/Template/js/custom/general.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/Template/js/plugins/jquery.jgrowl.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/Template/js/plugins/jquery.alerts.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/Template/js/custom/elements.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/Template/js/plugins/colorpicker.js")"></script>
<script src="http://code.jquery.com/jquery-1.9.0.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.js"></script>
General.js
jQuery(document).ready(function()
{
//search box of header
jQuery('#keyword').bind('focusin focusout', function(e)
{
var t = jQuery(this);
if(e.type == 'focusin' && t.val() == 'Search here')
{
t.val('');
}
else if(e.type == 'focusout' && t.val() == '')
{
t.val('Search here');
}
});
jQuery( "#keyword" ).autocomplete({
source: availableTags
});
}
以上产生了:
未捕获的TypeError:jQuery(...)。autocomplete不是函数
at HTMLDocument.<anonymous> (general.js:373)
at fire (jquery-1.10.2.js:3048)
at Object.fireWith [as resolveWith] (jquery-1.10.2.js:3160)
at Function.ready (jquery-1.10.2.js:433)
at HTMLDocument.completed (jquery-1.10.2.js:104)
我的搜索框甚至没有显示,我怀疑这是我一直遇到的这些错误的结果。
答案 0 :(得分:1)
要纠正的一些事情:
1)<script src="//code.jquery.com/jquery-1.10.2.js"></script>
然后<script src="http://code.jquery.com/jquery-1.9.0.js"></script>
。不要包含jQuery两次。包括更新的版本,并在所有其他脚本之前包含一次。换句话说,删除对1.9.0的引用。然后看看你是否还有问题。包括它两次会导致奇怪的冲突。
2).bind
在jQuery 1.7中被.on
取代,在3.0中被弃用。使用.on
获得前向兼容性和更好的功能。
答案 1 :(得分:1)
jQuery(function ($) {
$(function () {
$...............
});});