【问题标题】:How to change new version jquery code to old version of code如何将新版本的jquery代码更改为旧版本的代码
【发布时间】:2020-06-29 09:10:34
【问题描述】:

我想更改以下代码以兼容 jquery 1.4.1 版

$(document).on("change","select",function(){
      $("option[value=" + this.value + "]", this)
  .attr("selected", true).siblings()
  .removeAttr("selected")
});

【问题讨论】:

  • 你试过什么?当你尝试时失败了什么?
  • Uncaught TypeError: $(...).setValue is not a function
  • Uncaught TypeError: Cannot read property 'destroy' of undefined
  • 出现这些错误
  • 请附上尝试的代码,以便我们查看您拥有的内容,这样会更容易指导您。

标签: javascript jquery


【解决方案1】:

on 处理程序是在 v1.7 中添加的。在此之前,您可以使用 live 处理程序,它是在 1.3 中添加并在 1.7 中贬值

例如:

$(document).ready(function() {
 $("select").live("change", function() {  
    console.log('change event ' + this.value)   
  });
});

请注意,如果您的下拉列表是静态内容,您可以使用 change 处理程序。

http://jsfiddle.net/tg8y6nos/1/

【讨论】:

  • 感谢您的回答,但它不适用于 jquery 1.4 版
  • 您是在动态创建选择 html 吗?您还可以提供更多代码
  • 检查此问题代码,该代码负责创建选项stackoverflow.com/questions/62632597/…
  • 您的代码正在动态添加选项。但是很难说选择 html 是如何生成的。希望现场处理程序能解决问题。
  • 好的@Greg让我检查一下
猜你喜欢
  • 2017-05-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-12
  • 2022-12-22
  • 1970-01-01
  • 2020-12-03
相关资源
最近更新 更多