我需要创建select2,我可以选择多个值。但我每次都收到“没有找到结果”的消息,尝试了各种解决方案但没有任何效果。我真的不知道什么是错的。
<select id="keywords-input" multiple="multiple" style="width:300px">
{*
<option selected="selected" value="Val 1">Val 1</option>*} {*
<option selected="selected" value="Val 2">Val 2</option>*} {*
<option selected="selected" value="Val 3">Val 3</option>*} {*
<option selected="selected" value="Val 4">Val 4</option>*} {*
<option selected="selected" value="asfsafafsa">asfsafafsa</option>*}
</select>
<script>
$(document).ready(function() {
$('#keywords-input').select2({
tags: true,
tokenSeparators: [',', ' '],
data: ['Val1', 'Val2', 'Val3'],
maximumInputLength: 10,
multiple: true
});
});
</script>
你的代码对我来说很好用:
HTML
<select id="keywords-input" multiple="multiple" style="width:300px">
{*
<option selected="selected" value="Val 1">Val 1</option>*} {*
<option selected="selected" value="Val 2">Val 2</option>*} {*
<option selected="selected" value="Val 3">Val 3</option>*} {*
<option selected="selected" value="Val 4">Val 4</option>*} {*
<option selected="selected" value="asfsafafsa">asfsafafsa</option>*}
</select>
JS
$(document).ready(function() {
$('#keywords-input').select2({
tags: true,
maximumInputLength: 10,
});
});
它是由另一个使用select2类的javascript引起的,现在它可以工作了。所以我的代码没错。