7

I'm using jquery-select2 4.0.0 and I want to display a text containing an '&'.

This is the code of the option:

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

However, Select2 shows the following as the option text:

123 - This &amp; That

How can I get Select2 to show the specialchar correctly?

4

1 回答 1

11

escapeMarkup您可以在选项的帮助下解决这个问题。

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

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

这是jsfiddle 上的演示。

您应该查看这个 GitHub 问题escapeMarkup 在文档中查找。

于 2015-03-10T15:00:20.467 回答