2009-11-25 82 views
0

是否有可能使用jQuery來驗證以下HTML選擇列表是否包含任何項目?選擇列表內容的jQuery驗證

HTML選擇最初爲空的國家列表,除非填充,否則可能會保持原樣。

<select size="5" name="Country" multiple="multiple" id="Country"> 
</select> 
+0

大家乾杯! – 2009-11-25 16:52:22

回答

2

當select中有項目時,這將返回true。

alert($("#Country").children().length > 0); 
1
if($('#Country').children().length > 0) { 
    ... 
} 
0
if (0 == $('#Country option').length) { 
    // no options 
} else { 
    // options! 
} 
0
$("#Country option").length > 0