繁体   English   中英

如何使用jQuery在下拉列表中的“选定”属性中获得#选项?

[英]How to get the # of options with the attr “selected” in a drop down using jQuery?

这对我不起作用:

    $('select').each(function() {  

        alert($(this).find('option').attr('selected').length);

    }

实际上,我真正需要的只是检测当前选择是否具有任何预选选项。

您可以使用:selected选择器:

alert($(this).find("option:selected").length);

或者,将this用作选择器的上下文:

alert($("option:selected", this).length);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM