对象不支持“最近”的属性或方法

杰伯特兰

我刚刚得到的信息是我的jQuery函数无法在IE或Edge上运行。在控制台中,我收到消息:

对象不支持“最近”的属性或方法

这是jQuery:

$('body').on('change', 'select', function (event) {
    if(event.target.id.indexOf("couche") >= 0) {
        $.ajax({
            url: "{{ redir2 }}",
            type: "POST",
            data: {
                ident: event.target.id,
                value: event.target.value,
                iscouche: "True"
            },
        }).done(function (msg) {
            if(msg.nothing == 1) {
                var what = event.target.closest('tbody');
                $(what).find("tr:gt(0)").remove();
            } else {
                var add = event.target.closest('tr');
                var toremove = msg.toremove.split(" ");
                for(var i = 0; i < toremove.length; i++) {
                    if(toremove[i].length > 0) {
                        jQuery(toremove[i]).remove();
                    }
                }
                jQuery(add).after(msg.ret);
            }
        });

    } else {
        $.ajax({
            url: "{{ redir2 }}",
            type: "POST",
            data: {
                ident: event.target.id,
                value: event.target.value,
                iscouche: "False"
            },
        }).done(function (msg) {});
    }
});

有人可以告诉我是否有解决办法?

普伦贡

event.target 是DOM节点,而不是jQuery对象,因此没有jQuery方法

在jQuery中,请改用$(this)jQuery对象。

我还建议您在不需要时不要使用目标。

更新:较新的浏览器现在具有最接近的DOM方法,因此OPs代码将在除IE之外的较新的浏览器中工作。

这是固定的jQuery版本:

$('body').on('change', 'select', function(event) {
  var $sel = $(this),    // the changed select
    id = this.id,        // or $(this).attr("id"); 
    val = $(this).val(); // or this.value
  if (id.indexOf("couche") >= 0) {
    $.ajax({
      url: "{{ redir2 }}",
      type: "POST",
      data: {
        ident: id,
        value: val,
        iscouche: "True"
      },
    }).done(function(msg) {
      if (msg.nothing == 1) {
        var what = $sel.closest('tbody')
        $(what).find("tr:gt(0)").remove();
      } else {
        var add = $sel.closest('tr');
        var toremove = msg.toremove.split(" ")
        for (var i = 0; i < toremove.length; i++) {
          if (toremove[i].length > 0) {
            jQuery(toremove[i]).remove();
          }
        }
        jQuery(add).after(msg.ret);
      }
    });

  } else {
    $.ajax({
      url: "{{ redir2 }}",
      type: "POST",
      data: {
        ident: id,
        value: val;,
        iscouche: "False"
      },
    }).done(function(msg) {});
  }
});

或更整洁:

$('body').on('change', 'select', function(event) {
  var $sel = $(this), // the select changed
    val = this.value,
    id = this.id,
    isCouche = id.indexOf("couche") != -1;
  $.ajax({
    url: "{{ redir2 }}",
    type: "POST",
    data: {
      ident: id,
      value: val,
      iscouche: isCouche ? "True" : "False";
    },
  }).done(function(msg) {
    if (isCouche) {
      if (msg.nothing == 1) {
        var what = $sel.closest('tbody')
        $(what).find("tr:gt(0)").remove();
      } else {
        var add = $sel.closest('tr');
        var toremove = msg.toremove.split(" ")
        for (var i = 0; i < toremove.length; i++) {
          if (toremove[i].length > 0) {
            $(toremove[i]).remove();
          }
        }
        $(add).after(msg.ret);
      }
    } else {
      // handle not couche
    }
  });
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

VBA对象不支持此属性或方法

来自分类Dev

对象不支持属性或方法“删除”

来自分类Dev

对象不支持属性或方法“绑定”-Backbone.js

来自分类Dev

对象不支持此属性或方法

来自分类Dev

HTML画布-对象不支持属性或方法“删除”

来自分类Dev

对象不支持IE 10中的属性或方法“ querySelector”

来自分类Dev

对象不支持属性或方法“ kendoDatePicker”

来自分类Dev

对象不支持属性或方法“ attachEvent” InternetExplorer 11

来自分类Dev

对象在jQuery中不支持属性或方法“查找”

来自分类Dev

IE 11错误:对象不支持属性或方法“替换”

来自分类Dev

对象不支持属性或方法“键”-(IE11)

来自分类Dev

下拉Javascript错误:对象不支持属性或方法“匹配”

来自分类Dev

对象在igGrid中不支持属性或方法“ _super”

来自分类Dev

对象不支持属性或方法“填充”

来自分类Dev

对象不支持属性或方法“ readFile”(节点:fs)

来自分类Dev

“对象不支持属性或方法” VBA登录

来自分类Dev

对象不支持此属性或方法ActiveWorkbook对象VBA

来自分类Dev

对象不支持此属性或方法

来自分类Dev

$对象不支持'live'属性或方法

来自分类Dev

对象不支持“前缀”的属性或方法

来自分类Dev

对象不支持此属性或方法

来自分类Dev

对象不支持“打开”属性或方法

来自分类Dev

对象不支持属性或方法“推”

来自分类Dev

对象不支持属性或方法“ setMap”

来自分类Dev

对象不支持属性或方法getUserData

来自分类Dev

对象不支持属性或方法“多选”

来自分类Dev

对象不支持属性或方法“.DataLabels”

来自分类Dev

“对象不支持属性或方法‘包含’”-[对象错误]

来自分类Dev

对象不支持此属性或方法

Related 相关文章

热门标签

归档