2013-12-17 46 views
1

我想將圖像和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> 
+0

[選擇模板](HTTP:// ivaynberg .github.io/select2 /#templating) – Tomanow

回答

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>"; 
     } 
+0

偉大的答案兄弟 – 2014-01-30 07:45:19

相關問題