【问题标题】:How to get jquery-select2 to display html entities correctly?如何让 jquery-select2 正确显示 html 实体?
【发布时间】:2015-05-12 01:20:50
【问题描述】:
我正在使用 jquery-select2 4.0.0,我想显示一个包含“&”的文本。
这是选项的代码:
<option value="123">
123 - This & That
</option>
但是,Select2 将以下内容显示为选项文本:
123 - This & That
如何让 Select2 正确显示特殊字符?
【问题讨论】:
标签:
jquery
jquery-select2
jquery-select2-4
【解决方案1】:
您可以在 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 并寻找escapeMarkup on the documentation。