检测具有相同类的其他项目,而不是使用not(this)

Detect other items with same class other than with not(this)

本文关键字:not this 同类 项目 其他 检测      更新时间:2023-09-26

在某些情况下,选择除当前类别之外的具有相同类别的所有项目非常方便:

$('.checkbox_handler').not(this).prop('disabled');

其工作良好。但现在我遇到了this的一个小问题(双关语)。在启用此规则的情况下,我将ESlint用于任何JS/jQuery linting。从那以后,我不断地收到no-invalid-this Unexpected 'this'错误。

我现在的问题是:有没有办法使用.not(this)来检测任何不是当前元素的相同类。还是我没有看到大局?

编辑:根据要求显示更多代码

{
  otherFunctions: function() {},
  disableInput: function(selector) {
    $(selector).on('change', function() {
      $('.checkbox_handler').not(this).prop('disabled', function(i, value) {
        return !value;
      });
    });
  }
}

完全标记。所有这些都在一个对象中,我正在其中迭代函数。

好的,所以你的js看起来是有效的。我建议将"e"或"event"作为处理程序的参数,并为"this"引用e.target。

https://developer.mozilla.org/en-US/docs/Web/API/Event/target