• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

js原生实现条

武飞扬头像
小橙几
帮助1

实现思路:
1.定義一個流程數組和一个步骤状态
2.遍历这个流程数组,如果步骤状态大于流程,checked=true,
3.页面输出遍历的流程数组,checked的div点亮
最终效果
学新通

<!DOCTYPE html>
<html>
<title>js原生实现步骤条</title>
<head>
<style type="text/css">
#wrapper {
    /* background-color: pink; */
}
#stepBox {
  display: flex;
  align-items: center;
}
#stepBox .step-item {
  display: flex;
  align-items: center;
  margin-left: 2px;
  /* border: 1px solid #000; */
}
.step-checked {
  color: #67c23a;
}
.step-item .line{
    display: inline-block;
    width: 100px;
    height: 2px;
    background-color: #c0c4cc;
}
.step-item .line-actived{
    width: 100px;
    height: 2px;
    background-color: #67c23a;
}
.button-box {
  display: flex;
}
.button {
  width: 80px;
  height: 40px;
  margin-top: 80px;
  line-height: 40px;
  text-align: center;
  border: 1px solid #000;
  cursor: pointer;
  border-radius: 5px;
  user-select: none;
}
.next-btn {
  margin-left: 20px;
}
</style>        
</head>
<body>
    <div id="wrapper">
      <div id="stepBox"></div>

      <div class="button-box">
        <div class="button" onclick="backLastStep()">上一步</div>
        <div class="button next-btn" onclick="nextStep()">下一步</div>
      <div>

    </div>
</body>
<script>
var currentStep = 1; // 目前到达的步骤
var someArray = [{
    stepName: '步骤1',
  }, {
    stepName: '步骤2',
  }, {
    stepName: '步骤3',
  }]
function renderStepList() {
    var elementArray = []
    for(let index=0;index<someArray.length; index  ){
        var isChecked = false
        var isChecked = ''
        if(index<currentStep) {
          isChecked = true
        }
        str = `<div class="step-item ${isChecked?'step-checked':''}">
          <span>${someArray[index].stepName}</span>
          ${index<someArray.length-1?
            `<i class="line ${isChecked?'line-actived':''}"></i>`:''
          }
          </div>`;
        elementArray.push(str)
    }
    document.getElementById("stepBox").innerHTML = elementArray.join('')
}
function nextStep () { // 点击下一步
  if(currentStep > someArray.length-1) {
    alert('没有下一步了')
    return
  }
  currentStep = currentStep   1
  this.renderStepList()
}
function backLastStep () { // 点击上一步
  if(currentStep < 0) {
    alert('没有上一步了')
    return
  }
  currentStep = currentStep - 1
  this.renderStepList()
}
renderStepList();
</script>
</html>


学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgefebe
系列文章
更多 icon
同类精品
更多 icon
继续加载