我们可以在列表标题中添加元素吗?

时间:2013-12-17 14:12:58

标签: jquery jquery-select2

我想将图像和1或2 div添加到select2元素中。

Here is the image how I like the output from the select 2. Is it possible?

这是我尝试过的代码:

<select style="width:94%"   id="e9">
 <option value="volvo">Suger</option>
 <option value="saab">Saab</option>
 <option value="opel">Opel</option>
 <option value="audi">Audi</option>
</select>

<script>
$("#e9").select2({ placeholder: 'testing',}); 
</scipt>

1 个答案:

答案 0 :(得分:0)

这里是您实际需要的答案......

$("#e9").select2({
     data:'passdatahere',
    formatResult: format,
    formatSelection: format,
    escapeMarkup: function(m) { return m; }
});

 function format(processElement) {
    return "<img class='flag' src='../images/i.png'/>
     <div style='display:inline-block;padding-left:15px'>" 
     + processElement.name + "</div>
     <div style='padding-left:30px'>
     <span class='icon-code-updated icon-doc-missing' style='display:inline-block'>
        </span>" + processElement.status + "</div>";
        }