【问题标题】:Update select2 option text on-the-fly?即时更新 select2 选项文本?
【发布时间】:2016-03-09 10:02:24
【问题描述】:

我想即时更改选项的文本。可以通过以下方式轻松更改 HTML:

$('option[value=custom-pub]').text("New Text For Pub");

如何强制 select2 刷新文本?我不想 destroy() 从头开始​​创建 select2 对象,因为我希望用户选择保持选中状态。

【问题讨论】:

    标签: jquery-select2 jquery-select2-4 select2


    【解决方案1】:

    简单

    $("select").select2();
    

    有效。

    【讨论】:

    • 这会重建整个 select2 控件,并预先重置任何提供的选项,要么重新提供选项,要么不使用它
    猜你喜欢
    • 2020-02-15
    • 2016-03-14
    • 2016-02-24
    • 2014-11-22
    • 1970-01-01
    • 1970-01-01
    • 2013-12-28
    • 2018-12-31
    • 1970-01-01
    相关资源
    最近更新 更多