jQuery
Get the selected country and then find the <option>
using attribute-equals-selector and hide the siblings
$(function () {
var country = $('.selected').data('country');
$('#CountryCode').find('[value="' + country + '"]').siblings().hide();
$('#CountryCode').val(country);
});
HTML
Add data-*
attribute to the html elements
<ul>
<li data-country="ARG">Argentina</li>
<li data-country="USA" class="selected">United States</li>
<li data-country="AUS">Australia</li>
</ul>
DEMO
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…