如何通过验证将进度条合并到垂直表单步骤中
How to incorporate progress bar in vertical form step with validation
我使用了下面 Jquery 个步骤中的垂直形式步骤
http://www.jquery-steps.com/Examples
一切正常。现在我想在没有 bootstrap 的情况下单击下一步按钮时显示带有验证的进度条。
有人可以帮忙做这个吗?
到目前为止我完成的代码,
$("#example-vertical").steps({
headerTag: "h3",
bodyTag: "section",
transitionEffect: "slideLeft",
stepsOrientation: "vertical"
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="example-vertical">
<h3>Keyboard</h3>
<div id="myProgress">
<div id="myBar">50%</div>
</div>
<section>
<p>Try the keyboard navigation by clicking arrow left or right!</p>
</section>
<h3>Effects</h3>
<section>
<p>Wonderful transition effects.</p>
</section>
<h3>Pager</h3>
<section>
<p>The next and previous buttons help you to navigate through your content.</p>
</section>
</div>
立即查看
var currentIndex;
var steps;
var wizardLength = $("#example-vertical").find('h3').length;
$("#example-vertical").steps({
headerTag: "h3",
bodyTag: "section",
transitionEffect: "slideLeft",
stepsOrientation: "vertical",
startIndex: 0,
currentIndex:1,
onInit:function (event, currentIndex) {
setProgressBar(currentIndex);
},
onStepChanged: function (event, currentIndex, priorIndex) {
setProgressBar(currentIndex);
//console.log(currentIndex);
//console.log(wizardLength);
},
});
// Change progress bar action
function setProgressBar(currentIndex) {
var percent = parseFloat(100 / wizardLength) * (currentIndex + 1);
percent = percent.toFixed();
$(".progress-bar")
.css("width", percent + "%")
.html(percent + "%");
}
#myProgress{
background: #eee;
}
.progress-bar{
background: green;
color: #fff;
text-align: center;
}
<link href="http://www.jquery-steps.com/Content/Examples.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-steps/1.1.0/jquery.steps.min.js"></script>
<div id="example-vertical">
<h3>Keyboard</h3>
<div id="myProgress">
<div id="myBar" class="progress-bar">50%</div>
</div>
<section>
<p>Try the keyboard navigation by clicking arrow left or right!</p>
</section>
<h3>Effects</h3>
<section>
<p>Wonderful transition effects.</p>
</section>
<h3>Pager</h3>
<section>
<p>The next and previous buttons help you to navigate through your content.</p>
</section>
</div>
我使用了下面 Jquery 个步骤中的垂直形式步骤
http://www.jquery-steps.com/Examples
一切正常。现在我想在没有 bootstrap 的情况下单击下一步按钮时显示带有验证的进度条。 有人可以帮忙做这个吗?
到目前为止我完成的代码,
$("#example-vertical").steps({
headerTag: "h3",
bodyTag: "section",
transitionEffect: "slideLeft",
stepsOrientation: "vertical"
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="example-vertical">
<h3>Keyboard</h3>
<div id="myProgress">
<div id="myBar">50%</div>
</div>
<section>
<p>Try the keyboard navigation by clicking arrow left or right!</p>
</section>
<h3>Effects</h3>
<section>
<p>Wonderful transition effects.</p>
</section>
<h3>Pager</h3>
<section>
<p>The next and previous buttons help you to navigate through your content.</p>
</section>
</div>
立即查看
var currentIndex;
var steps;
var wizardLength = $("#example-vertical").find('h3').length;
$("#example-vertical").steps({
headerTag: "h3",
bodyTag: "section",
transitionEffect: "slideLeft",
stepsOrientation: "vertical",
startIndex: 0,
currentIndex:1,
onInit:function (event, currentIndex) {
setProgressBar(currentIndex);
},
onStepChanged: function (event, currentIndex, priorIndex) {
setProgressBar(currentIndex);
//console.log(currentIndex);
//console.log(wizardLength);
},
});
// Change progress bar action
function setProgressBar(currentIndex) {
var percent = parseFloat(100 / wizardLength) * (currentIndex + 1);
percent = percent.toFixed();
$(".progress-bar")
.css("width", percent + "%")
.html(percent + "%");
}
#myProgress{
background: #eee;
}
.progress-bar{
background: green;
color: #fff;
text-align: center;
}
<link href="http://www.jquery-steps.com/Content/Examples.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-steps/1.1.0/jquery.steps.min.js"></script>
<div id="example-vertical">
<h3>Keyboard</h3>
<div id="myProgress">
<div id="myBar" class="progress-bar">50%</div>
</div>
<section>
<p>Try the keyboard navigation by clicking arrow left or right!</p>
</section>
<h3>Effects</h3>
<section>
<p>Wonderful transition effects.</p>
</section>
<h3>Pager</h3>
<section>
<p>The next and previous buttons help you to navigate through your content.</p>
</section>
</div>