2010-10-01 38 views

回答

1

你可以使用.selectedIndex(更快)或.index()爲此:

if($("#selectID")[0].selectedIndex == 0) { 
    alert("Please choose something"); 
} 
//or no jQuery at all: 
if(document.getElementById("selectID").selectedIndex == 0) { 

或選定<option>.index(),要慢得多,但工程:

if($("#selectID :selected").index() == 0) { 
    alert("Please choose something"); 
} 
0

給第一個選項的值爲 「0」:

<select id="#myselectionbox"> 
    <option value="0">Please select</option> 
    ... 
</select> 

,並檢查所選值:

if ($("#myselectionbox").val() != "0") { 
    // ok 
} 
0

你可以使用這樣的事情:

if ($("#yourselectid").val() == "Please ignore") { 
    alert("You must select another option."); 
}