我无权在下拉菜单中调整选项。所以我想将它们隐藏在DOM中。我在隐藏选项时遇到了麻烦。当前,如果我的数组包含要隐藏的国家/地区,则可以隐藏整个下拉列表。
https://jsfiddle.net/gmLa5bgz/
html
<select id="country_2">
<option value="AS">American Samoa</option><option value="AD">Andorra</option><option value="AO">Angola</option><option value="AI">Anguilla</option>
</select>
jQuery查询
var countries = new Array("France","Germany");
var i = 0;
var countryLength = countries.length;
for(i = 0; i < countryLength; i++) {
$('#country_2').each(function(){
if($(this).text().search(countries[i]) >= 0)
{$(this).remove();};
});
}
试试看:
var countries = new Array("France","Germany");
var i = 0;
var countryLength = countries.length;
for(i = 0; i < countryLength; i++) {
$('#country_2 option').each(function(){
if($(this).text()==countries[i])
{
$(this).remove();
}
});
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句