选择框在下拉菜单中隐藏第一个选项条目? [英] Selectbox hide first option entry on dropdown?
本文介绍了选择框在下拉菜单中隐藏第一个选项条目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当用户点击下拉框查看选项时,是否可以隐藏第一个选项,即< option>选择一个< /选项>
。因此,文本选择一个不会出现在列表中
Is it possible to hide the first option i.e. <option>Select One</option>
when the user clicks the dropdown box to see the options. So the text Select One does not appear in the list
推荐答案
由于没有可靠的跨浏览器隐藏选项
元素的方法,最好的办法就是在 focus
上删除它,然后再将它添加到 blur
:
As there is no reliable cross browser way to hide option
elements, your best bet is to remove it on focus
and add it again on blur
:
jQuery(document).ready(function () {
var first = jQuery('#myselect').find('option').first();
jQuery('#myselect').on('focus', function (e) {
first.remove();
}).on('blur', function (e) {
jQuery(this).find('option').first().before(first);
});
});
以下是工作示例
这篇关于选择框在下拉菜单中隐藏第一个选项条目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文