gpt4 book ai didi

jquery - 如何使用 jQuery 选择属性不透明度为 1 的元素

转载 作者:行者123 更新时间:2023-12-01 00:38:11 25 4
gpt4 key购买 nike

我有这些元素,我需要选择 ul 中的 li,其中 opacity=1。我怎样才能做到这一点?

<ul class="class" id="ul">
<li style="width: 100%; list-style: none outside none; position: absolute; top: 0px; left: 0px; z-index: 98; opacity: 0;"><a title="title1" href=""><img alt="alt" class="class_name" src="/images/7dfc294d5c3bcebecb2ec0e44fd27d1c.jpg"></a></li>
<li style="width: 100%; list-style: none outside none; position: absolute; top: 0px; left: 0px; z-index: 98; opacity: 0;"><a title="title2" href=""><img alt="alt" class="class_name " src="/images/a9c9eb42934df4576b352d88f607f292.jpg"></a></li>
<li style="width: 100%; list-style: none outside none; position: absolute; top: 0px; left: 0px; z-index: 98; opacity: 0;"><a title="title3" href=""><img alt="alt" class="class_name " src="/images/b64264692c0d648068c9d1380e9099c1.jpg"></a></li>
<li style="width: 100%; list-style: none outside none; position: absolute; top: 0px; left: 0px; z-index: 99; opacity: 1;"><a title="title4" href=""><img alt="alt" class="class_name " src="/images/43e3e5e2edc4234ecddbc89636e4e224.jpg"></a></li>
<li style="width: 100%; list-style: none outside none; position: absolute; top: 0px; left: 0px; z-index: 98; opacity: 0;"><a title="title5" href=""><img alt="e-alt" class="class_name " src="/images/31a156ce7f7ab5485366d24f6cbfbede.jpg"></a></li>
</ul>

最佳答案

$('#ul li').filter(function() {
return $(this).css('opacity') == '1';
});

<强> DEMO

您也可以尝试使用.each()

var lis = [];
$('#ul li').each(function() {
if ($(this).css('opacity') == '1') {
lis.push(this);
}
});

<强> DEMO

或使用.map()

var lis = $('#ul li').map(function() {
if($(this).css('opacity') == '1')
return this;
}).get();

<强> DEMO

关于jquery - 如何使用 jQuery 选择属性不透明度为 1 的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11170853/

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