<link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.2.0/css/bootstrap.min.css">
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<div class="stepsBox">
<ul class="list-unstyled">
<li class="stepBar alert alert-light">
<div class="stepTitle">步骤一</div>
<div class="stepContent">
<ol>
<li>
<div class="row">
<div class="col-md-8 text-left">
<div class="stepContentTitle">1.1 标题</div>
</div>
<div class="col-md-4 text-right">
<div class="stepFinishTime">
2024年8月1日 13:17:00
</div>
</div>
</div>
<div class="stepContentText">
Lorem
</div>
</li>
<li>
<div class="row">
<div class="col-md-8 text-left">
<div class="stepContentTitle">1.2 标题</div>
</div>
<div class="col-md-4 text-right">
<div class="stepFinishTime">
2024年8月1日 13:17:00
</div>
</div>
</div>
<div class="stepContentText">
Lorem
</div>
</li>
<li>
<div class="row">
<div class="col-md-8 text-left">
<div class="stepContentTitle">1.3标题</div>
</div>
<div class="col-md-4 text-right">
<div class="stepFinishTime">
2024年8月1日 13:17:00
</div>
</div>
</div>
<div class="stepContentText">
Lorem
</div>
</li>
</ol>
</div>
</li>
<li class="stepBar alert alert-secondary">
<div class="stepTitle">步骤二</div>
<div class="stepContent">
<ol>
<li>
<div class="row">
<div class="col-md-8 text-left">
<div class="stepContentTitle">2.1标题</div>
</div>
<div class="col-md-4 text-right">
<div class="stepFinishTime">
2024年8月1日 13:17:00
</div>
</div>
</div>
<div class="stepContentText">
Lorem
</div>
</li>
<li>
<div class="row">
<div class="col-md-8 text-left">
<div class="stepContentTitle">2.1标题</div>
</div>
<div class="col-md-4 text-right">
<div class="stepFinishTime">
2024年8月1日 13:17:00
</div>
</div>
</div>
<div class="stepContentText">
Lorem
</div>
</li>
</ol>
</div>
</li>
<li class="stepBar alert alert-secondary">
<div class="stepTitle">步骤三</div>
<div class="stepContent">
<ol>
<li>
<div class="row">
<div class="col-md-8 text-left">
<div class="stepContentTitle">3.1标题</div>
</div>
<div class="col-md-4 text-right">
<div class="stepFinishTime">
2024年8月1日 13:17:00
</div>
</div>
</div>
<div class="stepContentText">
Lorem
</div>
</li>
<li>
<div class="row">
<div class="col-md-8 text-left">
<div class="stepContentTitle">3.2标题</div>
</div>
<div class="col-md-4 text-right">
<div class="stepFinishTime">
2024年8月1日 13:17:00
</div>
</div>
</div>
<div class="stepContentText">
Lorem
</div>
</li>
<li>
<div class="row">
<div class="col-md-8 text-left">
<div class="stepContentTitle">3.3标题</div>
</div>
<div class="col-md-4 text-right">
<div class="stepFinishTime">
2024年8月1日 13:17:00
</div>
</div>
</div>
<div class="stepContentText">
Lorem
</div>
</li>
<li>
<div class="row">
<div class="col-md-8 text-left">
<div class="stepContentTitle">3.4标题</div>
</div>
<div class="col-md-4 text-right">
<div class="stepFinishTime">
2024年8月1日 13:17:00
</div>
</div>
</div>
<div class="stepContentText">
Lorem
</div>
</li>
</ol>
</div>
</li>
</ul>
<div class="btnBox d-flex justify-content-between">
<button
type="button"
class="btn btn-secondary previousBtn"
disabled
>
上一步
</button>
<button type="button" class="btn btn-primary nextBtn">
下一步
</button>
</div>
<div class="progressBar"></div>
</div>
$(document).ready(function () {
$('.stepsBox .stepBar').eq(0).find('.stepContent > ol > li').eq(0).addClass('activeBox');
$('.nextBtn').on('click', function () {
var currentStep = $('.stepsBox .stepBar').find('.activeBox');
var nextStep = currentStep.next();
if (nextStep.length) {
$('.stepsBox .stepContent ol li').each(function () {
$(this).removeClass('activeBox');
});
debugger
nextStep.addClass('activeBox');
var currentStepBar = currentStep.closest('.stepBar');
var nextStepBar = currentStepBar.next('.stepBar');
var currentStepIndex = currentStep.index();
var nextStepBarLength = nextStepBar.find('.stepContent > ol > li').length;
if (currentStepIndex === nextStepBarLength - 1 && nextStepBar.length) {
currentStepBar.removeClass('alert-light').addClass('alert-secondary');
nextStepBar.removeClass('alert-secondary').addClass('alert-light');
nextStepBar.find('.stepContent > ol > li').eq(0).addClass('activeBox');
if (!nextStepBar.next('.stepBar').length) {
$(this).removeClass('btn-primary').addClass('btn-secondary').attr('disabled', 'disabled');
}
}
} else {
$(this).removeClass('btn-primary').addClass('btn-secondary').attr('disabled', 'disabled');
}
});
});
默认给第一个stepBar添加activeBox,点击下一步li增加CSS activeBox,移除上一个;
如果下一个stepBar增加CSS alert alert-light,移除上一个并增加CSS alert alert-secondary;
如果是最后一个li 点击下一步Btn 增加btn-secondary disabled,上一步同理。
写了一半,越来越乱,求点思路,谢谢。
效果图: