zoukankan      html  css  js  c++  java
  • 简单三级联动

    <select id="brand">
      <option>—请选择—</option>
    </select>
    <select id="s_cpu">
      <option>—请选择—</option>
    </select>
    <select id="spec">
      <option>—请选择—</option>
    </select>
    let brand = ['英特尔', 'amd']
      let cpu = [
        ['i5', 'i7'],
        ['2700', '2700X']
      ]
      let spe = [
        [
          ['5840', '5740', '5640'],
          ['7700k', '8700k', '9700k'],
        ],
        [
          ['max', 'max s', 'max ss'],
          ['sss', 's max', 'max']
        ]
      ]
      // 获取
      let s = document.getElementById('brand')
      let s_cpu = document.getElementById('s_cpu')
      let spec = document.getElementById('spec')
      //for循环使js里的brand元素添加到s里
      for (let i = 0; i < brand.length; i++) {
        let option = new Option(brand[i], i)
        s.appendChild(option)
      }
      // 事件
      let types
      s.onchange = function () {
        s_cpu.options.length = 1
        spec.options.length = 1
        let index = this.value
        let shi = cpu[index]
        types = spe[index]
        for (let i = 0; i < shi.length; i++) {
          let option = new Option(shi[i], i)
          s_cpu.appendChild(option)
        }
      }
      s_cpu.onchange = function () {
        spec.options.length = 1
        let index = this.value
        let scpu = types[index]
        for (let i = 0; i < scpu.length; i++) {
          let option = new Option(scpu[i], i)
          spec.appendChild(option)
        }
      }

     动态追加tr

    <table id="db">
    </table>
      let table = document.getElementById('db')
    
      for (let i = 0; i < 5; i++) {
        let tr = document.createElement('tr')
        tr.innerHTML = '<td>' + i + '</td>'
        table.appendChild(tr)
      }
  • 相关阅读:
    华为上机练习题--求两个数组的总和
    C++设计模式之状态模式(四)
    深入理解java嵌套类和内部类
    c++实现精确计时
    Linux-中断和中断处理
    使用C#对MongoDB中的数据进行查询,改动等操作
    淘特房产CMS系统 7.5
    sass03 变量、样式导入
    sass02
    sass01
  • 原文地址:https://www.cnblogs.com/ronle/p/11042293.html
Copyright © 2011-2022 走看看