将宽度li's添加到父ul [英] add width li's to parent ul
本文介绍了将宽度li's添加到父ul的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为每个子菜单计算li的宽度,然后将其放入ul元素.
i would like to calculate the width of the li's for each submenu en then put in the ul element.
示例
<ul>
<li>level 1</li>
<li>
<ul style="widht:??;"> // total width li's added here 70px
<li>level 2</li> // width of this li 20px
<li>level 2</li>/ width of this li 50px
</ul>
</li>
<li>level 1</li>
<li>level 1
<ul style="widht:??;"> // total width li's added here 70px
<li>level 2</li> // width of this li 20px
<li>level 2</li>/ width of this li 50px
</ul>
</li>
</ul>
我有这么便宜
if ('#menu li:has(ul) ul'){
$('li').each(function(){
widthParentUl += $(this).outerWidth(true)
});
$(this)parent.('ul').attr('style','width:' + widthParentUl +'px; display:block; background:red;');
}
推荐答案
thnx寻求帮助.我现在有了这个,它的宽度增加了.
thnx for the help. I have this now, it's add's the width to its parrent ul.
$('#menu ul li > ul').each(function(){
var liItems = $(this);
var Sum = 0;
if(liItems.children('li').length >= 1){
$(this).children('li').each(function(i, e){
Sum += $(e).outerWidth(true);
});
$(this).width(Sum+1);
}
});
这篇关于将宽度li's添加到父ul的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文