JQuery: Hide options of select according to option value

旧时模样 提交于 2019-12-12 09:39:12

问题


given following html

<select name="IBE1$IBE_NurFlug1$ddl_Abflughafen" id="IBE1_IBE_NurFlug1_ddl_Abflughafen" class="dropdownlist" style="width: 99%;">
<option value="Antalya;TR">Antalya</option>
<option value="Berlin;DE">Berlin</option>
<option value="Duesseldorf;DE">Duesseldorf</option>
<option value="Frankfurt;DE">Frankfurt</option>
<option value="Hamburg;DE">Hamburg</option>
<option value="Hannover;DE">Hannover</option>
<option value="Köln-Bonn;DE">Köln-Bonn</option>
<option value="Leipzig;DE">Leipzig</option>
<option value="München;DE">München</option>
<option value="Stuttgart;DE">Stuttgart</option>

How can I hide all options with ;TR in the value?

thx a lot in advance, greetings


回答1:


Try

$("select > option[value*='TR']").remove()

EDIT:

Or if you know that 'TR' is always at the end, then

$("select > option[value$='TR']").remove()

Not sure how much more efficient the above is compared to searching the entire value attribute.



来源:https://stackoverflow.com/questions/3164690/jquery-hide-options-of-select-according-to-option-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!