本来找到一个bootstrap-tagsinput的插件,可以很久没有更新了,还是基于2.3的版本,只能放弃。
插件使用jquery-tagsinput 1.3.6,github地址:https://github.com/xoxco/jQuery-Tags-Input
可以用 data-height 设置输入框的高度,默认是100px,这里示例初始化默认为100%,方便输入更多的值。
$(selector).tagsInput({
'autocomplete_url': url_to_autocomplete_api,
'autocomplete': { option: value, option: value},
'height':'100px',
'width':'300px',
'interactive':true,
'defaultText':'add a tag',
'onAddTag':callback_function,
'onRemoveTag':callback_function,
'onChange' : callback_function,
'delimiter': [',',';'], // Or a string with a single delimiter. Ex: ';'
'removeWithBackspace' : true,
'minChars' : 0,
'maxChars' : 0, // if not provided there is no limit
'placeholderColor' : '#666666'
});