this.map(function(i,e) { return $(e).height(); }).get();这个i,e形参怎么传进去的,具体是什么啊
答案:2 悬赏:20
解决时间 2021-03-17 04:03
- 提问者网友:失败的占卜者
- 2021-03-16 22:50
<script>
$.fn.equalizeHeights = function() {
var maxHeight = this.map(function(i,e) {
return $(e).height();
}).get();
return this.height( Math.max.apply(this, maxHeight) );
};
$('input').click(function(){
$('div').equalizeHeights();
});
问下这个里面i,e形参是怎么传进去的啊
最佳答案
- 二级知识专家网友:猎杀温柔
- 2021-03-16 23:56
// JS map循环的语法:
var new_array = arr.map(callback[, thisArg])
// 回调参数
Parameters
callback
Function that produces an element of the new Array, taking three arguments:
// 参数1
currentValue
The current element being processed in the array.
// 参数2
index
The index of the current element being processed in the array.
// 参数3
array
The array map was called upon.// 所以可以理解到map里面的i为参数1即当前值,e为参数2即下标
var maxHeight = this.map(function(i,e) {
// $(e) e为下标,每次取道下标为当前对象的高度
return $(e).height();
}).get();
var new_array = arr.map(callback[, thisArg])
// 回调参数
Parameters
callback
Function that produces an element of the new Array, taking three arguments:
// 参数1
currentValue
The current element being processed in the array.
// 参数2
index
The index of the current element being processed in the array.
// 参数3
array
The array map was called upon.// 所以可以理解到map里面的i为参数1即当前值,e为参数2即下标
var maxHeight = this.map(function(i,e) {
// $(e) e为下标,每次取道下标为当前对象的高度
return $(e).height();
}).get();
全部回答
- 1楼网友:兮沫♡晨曦
- 2021-03-17 01:24
你好!
参考$(selector).each(function(index,element)) 遍历所有div 其中 i 为索引值 e为对应div对象
代码结果就是将所有div高度变成最高的那个的高度
仅代表个人观点,不喜勿喷,谢谢。
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯