如何在下拉菜单中仅保留选项中的选项

时间:2022-01-14 20:10:18

How to keep only the select option remain visible in a dropdown menu.

如何仅保留选择选项在下拉菜单中仍然可见。

<select name="month" id="my_month">
<option value="01">January</option>
<option value="02">February</option>
<option value="03" selected="selected">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">Jun</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">Septembar</option>
<option value="10">Octobor</option><option value="11">Novembar</option>
<option value="12">Decembar</option>    
 </select>

From the dropdown, I wish to keep only 'select' part visible. Possible with CSS?

从下拉列表中,我希望只保留“选择”部分。可以用CSS吗?

Thanks

2 个解决方案

#1


1  

$("#my_month option").hide();

$("#my_month > option[selected==selected]").show();

$(“#my_month> option [selected == selected]”)。show();

#2


0  

I think it should be possible with CSS, but my stab at it doesn't quite work in Chrome and not nearly in IE.

我认为应该可以使用CSS,但是我对它的刺激并不适用于Chrome,也不适用于IE。

#my_month option { display: none;}
#my_month option[selected="selected"] { display: inline;}

This is a candidate for jQuery and there are at least a couple question that show some methods.

这是jQuery的候选者,并且至少有一些问题显示了一些方法。

jquery-and-css-hide-show-select-options-with-a-certain-css-class

how-to-hide-a-option-in-a-select-menu-with-css

#1


1  

$("#my_month option").hide();

$("#my_month > option[selected==selected]").show();

$(“#my_month> option [selected == selected]”)。show();

#2


0  

I think it should be possible with CSS, but my stab at it doesn't quite work in Chrome and not nearly in IE.

我认为应该可以使用CSS,但是我对它的刺激并不适用于Chrome,也不适用于IE。

#my_month option { display: none;}
#my_month option[selected="selected"] { display: inline;}

This is a candidate for jQuery and there are at least a couple question that show some methods.

这是jQuery的候选者,并且至少有一些问题显示了一些方法。

jquery-and-css-hide-show-select-options-with-a-certain-css-class

how-to-hide-a-option-in-a-select-menu-with-css