使用场景是:一个下拉框有太多值 需要搜索做匹配
一:加载文件
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
二:html代码
<select name="hospital_id" id="searchHospital">
<option value="0">请选择医院</option>
<foreach name="hospitalData" item="list">
<option value="{$list.hospital_id}"
<if condition="$_GET['hospital_id'] eq $list['hospital_id']">selected</if>>
{$list.hospital_name}
</option>
</foreach>
</select>
三:js
<script>
$(function(){
$('#searchHospital').select2({
placeholder: "Select a state"
});
});
</script>