0
我使用Bootstrap tag plugin,我成功地使用此代码一些标签添加到它:如何将默认值添加到引导程序标签选择输入?
$(function() {
var data = [{"id":"1","value":"painting-works"},{"id":"2","value":"plumbing-works"},{"id":"3","value":"programming"}];
var states = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: data
});
states.initialize();
$("#tags").tagsinput({
itemValue: 'id',
itemText: 'value',
allowDuplicates: false,
maxTags: 1,
typeaheadjs: {
name: "states",
displayKey: 'value',
source: states.ttAdapter(),
},
freeInput: true
});
});
和输入元素是
<select placeholder="" class="bootstrap-tagsinput" id="tags"></select>
我已经试过这个代码
$('#tags').tagsinput('add', 'new');
但它只是增加了一个新的标签 ,我试图使用jQuery
$('#tags').val("painting-works");
,但它没有工作,我该怎么办?
为什么不你使用“输入类型文本”而不是下拉菜单?然后使用:$('#tags')。tagsinput('add','new'); –