【发布时间】:2017-10-19 08:27:23
【问题描述】:
我写了这个脚本
$.ajax({
type: "POST",
url: "/my/GetTagsByID",
data: {
Link_ID: LId
},
datatype: "json",
success: function(result) {
$('#tokenfield-typeahead').val('Success 1, Success 2')
},
error: function(jqXHR) {
alert(jqXHR.status);
}
})
问题是,但我不知道SCRIPTS 的确切位置应该是什么
当我以这种方式向上时:
<script src="~/Scripts/jquery-1.10.2.js"></script>
<script src="~/Scripts/dist/typeahead.bundle.js"></script>
<link href="~/Scripts/dist/css/tokenfield-typeahead.css" rel="stylesheet" />
<script src="~/Scripts/dist/bootstrap-tokenfield.js"></script>
<link href="~/Scripts/dist/css/bootstrap-tokenfield.css" rel="stylesheet" />
这意味着,我可以使用 TokenField 和 TypeAhead,但它不会替换值 $('#tokenfield-typeahead').val('Success 1, Success 2'),这意味着我无法访问 jQuery?
但是当我将Jquery 脚本的位置切换到这个位置时(将 JQUERY 移到底部):
<script src="~/Scripts/dist/typeahead.bundle.js"></script>
<link href="~/Scripts/dist/css/tokenfield-typeahead.css" rel="stylesheet" />
<script src="~/Scripts/dist/bootstrap-tokenfield.js"></script>
<link href="~/Scripts/dist/css/bootstrap-tokenfield.css" rel="stylesheet" />
<script src="~/Scripts/jquery-1.10.2.js"></script>
我不能使用Tokenfield,我不能再使用TypeAhead了。
我该怎么办?
添加了新代码 我添加了新代码,似乎 JQuery 无法将 tokenfiled 识别为函数 - 我如何在添加了所有必需引用的地方解决这个问题 - 请参阅下面的代码(我在控制台中遇到相同的错误,无论我在哪里test) - 请运行代码并点击按钮
$('#bt').click(function() {
$('#tokenfield-typeahead').tokenfield('setTokens', ['blue', 'red', 'white']);
});
<link href="http://sliptree.github.io/bootstrap-tokenfield/dist/css/bootstrap-tokenfield.css" rel="stylesheet" />
<link href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script src="http://sliptree.github.io/bootstrap-tokenfield/dist/bootstrap-tokenfield.js"></script>
<input type="text" class="form-control" id="tokenfield-typeahead" value="Temp 1, Temp 2" data-limit="10" placeholder="Enter tags" />
<button id="bt">Click me</button>
【问题讨论】:
标签: jquery html asp.net-mvc typeahead bootstrap-tokenfield