1
Select2插件未顯示帶有templateFormat選項的選定選項 任何人都知道如何修復它?Jquery選擇2未顯示選定值
標記:
<select id="plans" style="width: 75%">
<option value="1" name="text1" price="$1" saving="text" selected="selected"></option>
<option value="2" name="text2" price="$2" saving="text" selected="selected"></option>
JS:
$(document).ready(function() {
$('select#plans').select2({
minimumResultsForSearch: Infinity,
templateResult: formatState
});
});
function formatState(state) {
if (!state.id) return state.text;
var html = '<span class="name">' + state.element.attributes.name.value + "</span>"
html += '<span class="price">' + state.element.attributes.price.value + </span>"
html += '<span class="saving">' + state.element.attributes.saving.value + "</span>"
var $state = $(html);
return $state
}
這裏是上面的代碼的fiddle
謝謝
是,它的工作......非常感謝你 – Rafael