标签的占位符

时间:2014-09-01 11:32:21

标签: javascript jquery-select2

是否可以为Select2标签控件设置占位符?

$(containerID).select2({
    multiple: true,
    tags: allTags,
    placeholderOption: "Tags"
});

placeholderOption对于选择工作正常,但对于标签没有效果。

2 个答案:

答案 0 :(得分:1)

我认为除了输入中的placeholder属性之外,您不需要任何其他内容,例如:

<input type="hidden" id="select2-input" 
    placeholder="Tags placeholder" style="width:300px" />

<script>
    $("#select2-input").select2({
        tags: [],
    });
</script>

答案 1 :(得分:0)

在select2()内部执行此操作的替代方法,而不是使用内联HTML属性

$(containerID).select2({
    placeholder: "No tags yet, type here to tag",
    tags: [],
});
相关问题