[英]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.