【问题标题】:How to change Select2 default new tags key "tab" to "space"?如何将 Select2 默认的新标签键“tab”更改为“space”?
【发布时间】:2013-04-29 13:52:19
【问题描述】:

我正在为我的标签编辑器使用 Select2 的标签支持,我知道您可以通过输入标签并按“tab”键来添加一个不存在的标签

我的问题是:我不希望任何标签包含空格,例如“空格标签”, 那么有没有办法将“空格”键设置为新的标签触发器?

【问题讨论】:

    标签: javascript jquery jquery-select2


    【解决方案1】:

    (在问题编辑中回答。转换为社区 wiki 答案。参见Question with no answers, but issue solved in the comments (or extended in chat)

    OP 写道:

    经过一番挖掘,我解决了我的问题

    $("#e20").select2({
            tags:["red", "green", "blue"],
            tokenSeparators: [",", " "]
     });
    

    关键是tokenSeparators属性。

    document of Select2 很有用。

    【讨论】:

    • 如何在select2中创建keydown事件?我想触发空格键的事件
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-12
    • 1970-01-01
    • 1970-01-01
    • 2015-07-08
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    相关资源
    最近更新 更多