Select2始终显示“未找到结果”消息

问题描述 投票:0回答:2

我需要创建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>

The result

html tags jquery-select2
2个回答
1
投票

你的代码对我来说很好用:

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,
        });
    });

Jsfiddle


1
投票

它是由另一个使用select2类的javascript引起的,现在它可以工作了。所以我的代码没错。

© www.soinside.com 2019 - 2024. All rights reserved.