【发布时间】:2017-05-29 21:48:03
【问题描述】:
我正在考虑在 Asp.net 视图中为我的一个输入字段添加自动完成功能,因此我尝试了 Jquery UI 中的示例并将代码粘贴到其中一个 .cshtml 视图中:
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var data = ["Boston Celtics", "Chicago Bulls", "Miami Heat", "Orlando Magic", "Atlanta Hawks"];
$("#seed_one").autocomplete({source:data});
});
</script>
</head>
<body>
<input id="seed_one" type="text" name="seed_one" />
</body>
</html>
但是,当我运行应用程序并开始在输入字段中输入内容时,没有显示任何建议。代码有什么问题?
【问题讨论】:
-
检查您的浏览器控制台以查看是否有任何脚本错误。您的代码工作正常jsbin.com/livajenuco/edit?html,js,output
-
这段代码运行良好jsfiddle.net/ajays871/j6p0ogjt
-
将
document.ready脚本放在body标签的末尾 -
我在 Chrome 调试中收到此错误:未捕获的 TypeError: $(...).autocomplete is not a function at HTMLDocument.
(Create:151) at fire (jquery-1.12 .4.js:3232) 在 Object.fireWith [as resolveWith] (jquery-1.12.4.js:3362) 在 Function.ready (jquery-1.12.4.js:3582) 在 HTMLDocument.completed (jquery-1.12. 4.js:3617) -
看看你的 jquery 版本,那不是旧版本吗?你在加载另一个 jquery 吗?要么是错误的版本,要么是你调用得太早了。
标签: javascript asp.net asp.net-mvc asp.net-core