从数组中获取数字并将此数字设置为其他函数的函数
Function which get number from array and set this number to other function
我对一些jquery代码有问题:)
情况如下:
-
我有一个包含数字的数组var arr。
-
我有一个函数get_number(),它从大堆
- 我有一个参数为inner_height(number)的函数,它可以获得元素的最大高度,并将该高度设置为其他元素
但有些东西崩溃了…:(
这是一个jsfiddle
HTML结构
<div id="slide-1">
<div class="inner-li">
<p>Lorem Ipsum...</p>
</div>
</div>
<div id="slide-2">
<div class="inner-li">
<p>Lorem Ipsum...</p>
</div>
</div>
<div id="slide-3">
<div class="inner-li">
<p>Lorem Ipsum...</p>
</div>
</div>
带数字的数组//将数字保存在阵列中
var arr = [];
$("div[id^='slide-']").each(function() {
arr.push(parseInt( $(this).attr('id').split('-')'[1] ));
});
从阵列中获取每个数字
// Get each number from array
function get_number() {
$.each(arr, function(i, v) {
return arr[i];
});
}
获取内部li元素的最大高度
// Get max-height of inner-li and set to the others with the same class
function inner_li_height(number) {
var heights = $("div[id^='slide-" + number + "'] .inner-li").map(function () {
return $(this).height();
}).get(),
maxHeight = Math.max.apply(null, heights);
console.log(maxHeight);
$("div[id^='slide-" + number + "'] .inner-li").height(maxHeight);
}
这里调用函数:
// Call function inner_li_height
inner_li_height(get_number);
如果有人能帮我,我会很高兴:)
试试这个在多个DOM对象上工作的函数:
// Get max-height of inner-li and set to the others with the same class
function inner_li_height(attr) {
$(attr).each(function(i,v) {
var heights = $(attr).map(function () {
return $(this).height();
}).get();
maxHeight = Math.max.apply(null, heights);
console.log(maxHeight);
$(attr).height(maxHeight);
});
}
inner_li_height('div[id^="slide-"] .inner-li');
jsfiddle:http://jsfiddle.net/hr993Lsj/1/
相关文章:
- 函数将输出nan而不是数字,为什么
- 通过jQuery函数将拉丁数字更改为波斯数字并添加逗号
- Javascript函数用于检查数字并返回
- PHP函数识别3个数字中最低的一个并更改其类
- 如何创建一个确定2个数字之间值的函数
- 增加一个数字并将其附加到函数
- 如何在JavaScript中使用此函数对范围内的所有数字求和
- 在javascript中对数字调用构造函数
- 为什么模块化幂函数在 Python 和 Javascript 中对于大数字的工作方式不同
- 类型错误:数字不是一个函数
- 如何将以下函数更改为字母数字输出
- 给定一个带有数字的数组,我如何编写一个递归函数,当 2 个元素加起来为一个目标时,它会在数组中查找索引
- 雄辩的Javascript:无法理解在sum函数中如何确定数字值
- 为什么可以't JavaScript构造函数创建字符串或数字
- Javascript:编写一个函数,接收一个数组,然后返回一个只有唯一数字的数组,只删除数组
- 谷歌地图API多段线创建失败;未捕获类型错误:数字不是函数;
- php中的函数或介于-200和200之间但不为零的数字
- 为什么由于数组中数字1的位置,我会从函数中得到不同的结果
- 可以避免在JavaScript中对isNaN()函数进行内部数字转换
- Javascript:接收对象并返回对象中描述的所有数字的列表的函数