2013-01-22 52 views
0

是否有任何原因,當用戶從下拉菜單中選擇一些東西時,下面的jquery不起作用。 (這是假設自動更新)jQuery沒有自動更新選擇

<script> 
$(document).ready(function() { 
                $("#state").change(function() { 
                this.form.submit(); 
}) 
}); 
</script> 


    <form action="avsafety.asp" method="get"> 



    <p>State:<br/> 
     <select id="state" name="state"> 
     <option label="ACT" value="ACT" <%if request.querystring("state") = "ACT" then response.write("selected") %>>ACT</option> 
     <option label="NSW" value="NSW" <%if request.querystring("state") = "NSW" then response.write("selected") %>>NSW</option> 
     <option label="QLD" value="QLD" <%if request.querystring("state") = "QLD" then response.write("selected") %>>QLD</option> 
     <option label="VIC" value="VIC" <%if request.querystring("state") = "VIC" then response.write("selected") %>>VIC</option> 
     <option label="SA" value="SA" <%if request.querystring("state") = "SA" then response.write("selected") %>>SA</option> 
     <option label="TAS" value="TAS" <%if request.querystring("state") = "TAS" then response.write("selected") %>>TAS</option> 
     <option label="WA" value="WA" <%if request.querystring("state") = "WA" then response.write("selected") %>>WA</option> 
     </select> 
     <input type="submit" value="Search" /> 
    </p> 

    </form> 
+3

您可能忽略了','在.change的'結束(函數(){});如果' –

+1

應該正常工作,提交表單並在每次選擇新選項時重新加載頁面就是你想要做什麼?分號是「可選」,但最好使用它們。 – adeneo

+1

它在做什麼?你會得到什麼錯誤? – j08691

回答

2

,如果你的選擇是動態變化

給它

 $(document).ready(function() { 

       $(document).on("change","select#state",function(e){ 
          $("form").submit(); 
           }); 

    }); 
+0

我將如何整合?相對較新的jQuery。謝謝。 – sephiith

+0

而不是$(「state」)。change(function(){});也作爲其他海報說提交表格不是選擇 – mikakun

0

this試試在你正在使用的指向功能的情況下select#state。換句話說,您不能發送表單,因爲選擇內沒有任何表單。相反,更改您的代碼是這樣的:

$("#state").change(function() { 
     $("form").submit(); 
}) 
0

$("#state").find("option:selected").change(function(){});