我想将图像和1或2 div添加到select2元素中。
这是我尝试过的代码:
<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 :(得分: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>";
}