How to add html placeholder to select2?

后端 未结 4 1705
南旧
南旧 2021-01-18 06:39

I want to add one icon to placeholder like this

$(\"#tag_list\").select2({
    allowClear: true,
    placeholder: \"         


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-18 07:05

    Select2 automatically escapes HTML markup.

    $("#tag_list").select2({
        allowClear: true,
        placeholder: "    inout your tags...",
        tags: ['a', 'b', 'c'],
        escapeMarkup : function(markup) { return markup; } // let our custom formatter work
    });
    

    By overriding the 'escapeMarkup' parameter you can force it to render plain HTML instead (by returning the unescaped HTML as is). This will affect both the placeholder AND the select data (select2 handles the placeholder as any data, thus escaping it).

    For more information, check the AJAX data example: Examples - Select2 | LoadingRemoteData

提交回复
热议问题