javascript - 在下拉更改时运行 jQuery 函数

标签 javascript jquery

我编写了一个当前在 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);
        }
    });
});

最佳答案

使用change()代替click():

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

关于javascript - 在下拉更改时运行 jQuery 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4910795/

相关文章:

javascript - Nodejs 异步更新插入问题

javascript - jQuery 多处理范围 slider 空闲到处理程序

javascript - JQuery 自动完成晚了 1 个字符

javascript - 如何在 python 中获取完整的网页(使用 javascript)

javascript - YAHOO.lang 的 jQuery 版本(isUndefined、isNull、isString 等)

java - 在复选框选择上启用/禁用选项卡

javascript - 在 ajax 调用中发布多个对象

javascript - 如何通过滚动按钮触发打开新标签页

javascript - extjs html 编辑器 4.2.1 中的 selectText

javascript - 以动态形式计算已检查的行数