jQuery select index of dropdownlist based upon number of elements and value of current selection
I have a form with multiple dropdownlists on it. Some of them possess multiple values, others posess a blank choice and another random choice.
Using jQuery how do I detect which dropdowns have the blank choice selected AND have only one other choice THEN select that other choice.
I got the selector开发者_StackOverflow中文版 part down,
$("[id*='_ddl']").each(function() {
but am not sure how to detect the number of choices available, and if the currently selected value is a blank.
Thanks!
$('select[id*=_ddl]').each(function() {
var itemCount = $('option', this).length;
var selectedText = $('option:selected', this).text();
if (selectedText.length === 0 && itemCount === 2) {
// do stuff
}
});
精彩评论