简体   繁体   English

在下拉更改时运行jQuery函数

[英]Run jQuery function on drop down change

I wrote a jQuery function that currently runs on Click Event. 我编写了一个当前在Click事件上运行的jQuery函数。 I need to change it so that it runs when a drop down box (Select- Option) value is changed. 我需要更改它,以便在更改下拉框(Select- Option)值时运行它。 Here is my code: 这是我的代码:

<form id="form1" name="form1" method="post" action="">
  <label>
    <select name="otherCatches" id="otherCatches">
      <option value="*">All</option>
    </select>
  </label>
</form>

$("#otherCatches").click(function() {
    $.ajax({
        url: "otherCatchesMap.php>",
        success: function(msg) {
            $("#results").html(msg);
        }
    });
});

Use change() instead of click() : 使用change()而不是click()

jQuery(document).ready(function(){
  $("#otherCatches").change(function() {
    $.ajax({
     url: "otherCatchesMap.php>",
     success: function(msg){
       $("#results").html(msg);
     }
   });
  });
});

http://api.jquery.com/change/ http://api.jquery.com/change/

$(function() {
    $("#otherCatches").change(function() {
       $(this).val() // how to get the value of the selected item if you need it
    });
});

$("#otherCatches").change(function () {
    //// Your code        
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM