gpt4 book ai didi

javascript - 如果元素可见,则自动增加步数

转载 作者:行者123 更新时间:2023-12-03 12:23:49 25 4
gpt4 key购买 nike

尝试自动增加表单的步骤号。表单的某些元素可能会隐藏或显示,具体取决于上面的答案。
HTML

<div class="confirmation-step">
<span class="step-number"></span>
</div>
<div class="confirmation-step" style="display:none;">
<span class="step-number"></span>
</div>
<div class="confirmation-step">
<span class="step-number"></span>
</div>

jQuery

$('.confirmation-step').each(function() {
if($(this).is(':visible')) {
//set variable stepNum
//Haven't come up with anything good yet
} else {}
$(this).find('.step-number').html(stepNum);
});

示例输出

<div class="confirmation-step">
<span class="step-number">1</span>
</div>
<div class="confirmation-step" style="display:none;">
<span class="step-number"></span>
</div>
<div class="confirmation-step">
<span class="step-number">2</span>
</div>

谢谢!

最佳答案

怎么样

$('.confirmation-step:visible .step-number').text(function(i) {return i+1;});

FIDDLE

关于javascript - 如果元素可见,则自动增加步数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24317024/

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