我想查看是否在選擇框中選擇了一個選項,如果沒有,我希望它提醒一個字符串。我指的是這個鏈接(Check if option is selected with jQuery, if not select a default),但它不起作用。如何檢查在使用jQuery的選擇框中是否未選擇任何選項?
這裏是我的代碼:
<select id="language" name="language">
<option value=""></option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
if(!$("#language option:selected").length) {
alert('no option is selected');
}
我幾乎複製鏈接的答案,但它仍然沒有工作。我錯過了什麼?
非常感謝! – zeckdude