所以这是我遇到的一个逻辑问题:
$('#id_country').change(function () { // ON CHANGE OF DROP DOWN
var countryShortCode = $(this).val();
$('#country-phone-code option').each(function () { //STRING MATCH AGAINST OTHER DROP DOWN
if ($(this).text() == countryShortCode) { //THE PROBLEM I NEED AN 'ELSE' IF NO STRING MATCH FOUND
alert("match found"); // (only one match will ever be found, if any)
}
});
});
如果没有字符串匹配,我需要执行一些代码。这是我目前无法做到的。
IE
$('#country-phone-code option').each(function () {
if ($(this).text() == countryShortCode) {
alert("");
} else {
//(if after traversing of each #country-phone-code option, no match was found, do something
}
为措辞不当的问题道歉。