【问题标题】:Run jQuery function on drop down change在下拉更改时运行 jQuery 函数
【发布时间】:2011-02-06 00:56:45
【问题描述】:

我编写了一个当前在 Click 事件上运行的 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);
        }
    });
});

【问题讨论】:

  • 我知道这类 cmets 不受欢迎,但尽管如此:谷歌搜索 jquery change 会为您提供 change() 函数的链接作为第一次点击:api.jquery.com/change

标签: javascript jquery


【解决方案1】:

使用change() 代替click()

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

【讨论】:

  • .change() 非常适合
【解决方案2】:

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

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

【讨论】:

    【解决方案3】:
    $("#otherCatches").change(function () { //// Your code });

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多