0

当用户从下拉列表中选择某些内容时,以下 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>
4

3 回答 3

2

如果您的选项动态更改

试一试

     $(document).ready(function() {

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

     });
于 2013-01-22T22:43:46.323 回答
0

this在您使用的函数的上下文中,它指向select#state. 换句话说,您不能发送表单,因为选择中没有表单。而是将您的代码更改为如下所示:

$("#state").change(function () {
         $("form").submit();
})
于 2013-01-22T22:45:51.520 回答
0

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

于 2013-01-22T22:46:29.823 回答