【问题标题】: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 &amp; 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

【讨论】:

  • 太好了。谢谢。
  • @Benni 很高兴我的回答很有用。如果此答案解决了您的问题,请花点时间检查如何accept an answer。谢谢!
猜你喜欢
  • 1970-01-01
  • 2021-03-20
  • 1970-01-01
  • 2011-03-28
  • 1970-01-01
  • 2022-12-07
  • 2015-08-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多