开发者

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
    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜