gpt4 book ai didi

javascript - 如何求和列表项的宽度顶部等于 0px

转载 作者:行者123 更新时间:2023-11-28 18:10:06 25 4
gpt4 key购买 nike

HTML:

<ul class="listul">
<li style="width:10px; top: 0px"></li>
<li style="width:10px; top: 0px"></li>
<li style="width:10px; top: 5643px"></li>
<li style="width:10px; top: 56px"></li>
</ul>

JS:

var top = $('.listul li').css('top');
var wT = 0;
if (top = '0px'){
$(this).each(function(){
wT += $(this).outerWidth();
});
alert(wT);
}

我想用 if(top = '0px') 求和 li 的宽度但是这是行不通的,请帮助我

最佳答案

要循环每个列表项并检查 top 值,您应该尝试:

$(function(){

var wT = 0;
var items = $('.listul li');
items.each(function(){
if($(this).css('top') == "0px"){
wT += $(this).outerWidth();
}
});
alert(wT);

});

参见 JsFiddle

关于javascript - 如何求和列表项的宽度顶部等于 0px,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18843385/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com