【发布时间】:2018-08-16 17:24:11
【问题描述】:
我正在尝试获取包含类 category 的元素的高度。我不想使用.each() 函数,但它似乎将整个文档返回给我。这是我的代码:
$('.category').each((index) => {
console.log($(this).height());
});
这还给我:
828(文档高度)..
有什么想法吗?
【问题讨论】:
标签: javascript jquery each
我正在尝试获取包含类 category 的元素的高度。我不想使用.each() 函数,但它似乎将整个文档返回给我。这是我的代码:
$('.category').each((index) => {
console.log($(this).height());
});
这还给我:
828(文档高度)..
有什么想法吗?
【问题讨论】:
标签: javascript jquery each
那是因为您使用的是箭头函数,binds the this value of the enclosing context。
使用普通的Function。
$('.category').each(function(index) {
console.log($(this).height());
});
我知道它们看起来很可爱,但它们不是常规函数的完美替代品。
【讨论】: