“Mostre HTML na opção Select2” Respostas de código

Mostre HTML na opção Select2

var data = [{
   id: 0,
   text: 'enhancement',
   html: '<div style="color:green">enhancement</div>'
}, {
   id: 1,
   text: 'bug',
   html: '<div style="color:red">bug</div><div><small>This is some small text on a new line</small></div>'
}];

function template(data) {
    return data.html;
}

$("select").select2({
   data: data,
   templateResult: template,
   escapeMarkup: function(m) {
      return m;
   }
});
Rajan Jain

SELECT2 Exemplo HTML

<html>
        <script src="https://code.jquery.com/jquery-2.2.4.js"></script>
        <link href="https://rawgit.com/select2/select2/master/dist/css/select2.min.css" rel="stylesheet" />
        <script src="https://rawgit.com/select2/select2/master/dist/js/select2.js"></script>

        <select id="example" style="width: 300px">
            <option></option>
            <option value="JAN">January</option>
            <option value="FEB">February</option>
            <option value="MAR">March</option>
            <option value="APR">April</option>
            <option value="MAY">May</option>
            <option value="JUN">June</option>
            <option value="JUL">July</option>
            <option value="AUG">August</option>
            <option value="SEP">September</option>
            <option value="OCT">October</option>
            <option value="NOV">November</option>
            <option value="DEC">December</option>
        </select>

        <script>
            window.onpageshow = function() {
                $('#example').select2({
                    allowClear: true,
                    placeholder: 'Select a month'
                });
            };
        </script>
</html>

Juice WRLD

Respostas semelhantes a “Mostre HTML na opção Select2”

Perguntas semelhantes a “Mostre HTML na opção Select2”

Mais respostas relacionadas para “Mostre HTML na opção Select2” em HTML

Procure respostas de código populares por idioma

Procurar outros idiomas de código