在下拉更改时运行jQuery函数

时间:2011-02-06 00:56:46

标签: javascript jquery

我编写了一个当前在Click Event上运行的jQuery函数。我需要更改它,以便在更改下拉框(Select- Option)值时运行它。这是我的代码:

<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);
        }
    });
});

3 个答案:

答案 0 :(得分:33)

使用change()代替click()

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

答案 1 :(得分:22)

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

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

答案 2 :(得分:11)


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