You have to add an empty option (i.e. <option></option>
) as a first element to see a placeholder.
From Select2 official documentation :
"Note that because browsers assume the first option element is selected in non-multi-value select boxes an empty first option element must be provided (<option></option>
) for the placeholder to work."
Hope this helps.
Example:
<select id="countries">
<option></option>
<option value="1">Germany</option>
<option value="2">France</option>
<option value="3">Spain</option>
</select>
and the Javascript would be:
$('#countries').select2({
placeholder: "Please select a country"
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…