在某些情况下,选择除当前项目之外的所有同一类别的项目非常方便:
$('.checkbox_handler').not(this).prop('disabled');
效果很好。
但现在我遇到了一个关于 this
的小问题(双关语)。我正在使用ESlint对于任何带有 this 的 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
关于javascript - 检测除 not(this) 以外具有相同类别的其他项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34600089/