我想知道是否可以通过 jquery 使用输入框过滤选择列表。
这是我的 js 的样子,但它似乎不起作用。我猜这是因为选择列表中的选项不可隐藏。
<script type="text/javascript">
$(document).ready(function() {
$("#inputFilter").change(function() {
var filter = $(this).val();
$("#selectList option").each(function() {
var match = $(this).text().search(new RegExp(filter, "i"));
if (match > 0) {
$(this).show(); // Does not work
}
else
$(this).hide();
});
});
});
</script>
这是我的html
<input id="inputFilter" />
<select id="selectList">
<option value="1111" >1111 - London</option>
<option value="1112" >1112 - Paris </option>
</select>