如何让 jquery-select2 正确显示 html 实体?

How to get jquery-select2 to display html entities correctly?

我正在使用 jquery-select2 4.0.0,我想显示包含“&”的文本。

这是选项的代码:

<option value="123">
   123 - This & That
</option>

但是,Select2 将以下内容显示为选项文本:

123 - This &amp; That

如何让 Select2 正确显示特殊字符?

您可以借助 escapeMarkup 选项解决这个问题。

<select id="s2">
    <option value="123">123 - This & That</option>
</select>

<script>
$(document).ready(function() {
    $('#s2').select2({
        escapeMarkup: function (text) { return text; }
    });
});
</script>

Here's the demo 在 jsfiddle 上。

你应该看看at this GitHub issue and look for escapeMarkup on the documentation