是否可以使用jQuery验证以下HTML选择列表是否包含任何项目?
HTML选择最初为空的国家/地区列表,除非已填充,否则可以保留。
<select size="5" name="Country" multiple="multiple" id="Country">
</select>
答案 0 :(得分:2)
当选择中有项目时,这将返回true。
alert($("#Country").children().length > 0);
答案 1 :(得分:1)
if($('#Country').children().length > 0) {
...
}
答案 2 :(得分:0)
if (0 == $('#Country option').length) {
// no options
} else {
// options!
}
答案 3 :(得分:0)
$("#Country option").length > 0