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)
      }
  • 相关阅读:
    [hihoCoder] #1093 : 最短路径·三:SPFA算法
    [hihoCoder] #1089 : 最短路径·二:Floyd算法
    [LeetCode] Number of Islands
    PRML5-神经网络(1)
    CUDA2.4-原理之性能优化及浮点运算
    PRML1-引言
    PGM1.1-简介
    AI1.1-人工智能史
    数学-矩阵计算(4)两种布局
    数学-矩阵计算(2)矩阵函数微积分前奏
  • 原文地址:https://www.cnblogs.com/ronle/p/11042293.html
Copyright © 2011-2022 走看看