欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

原生js實現(xiàn)二級聯(lián)動菜單

 更新時間:2019年11月27日 15:28:41   作者:濮家大少  
這篇文章主要為大家詳細介紹了原生js實現(xiàn)二級聯(lián)動菜單,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了js二級聯(lián)動菜單的具體代碼,供大家參考,具體內(nèi)容如下

效果如下:

代碼如下:

<!DOCTYPE html>
<html>
 <head>
 <meta charset="utf-8" />
 <title>二級聯(lián)動菜單</title>
 <style>
  *{
  padding: 0px;
  margin: 0px;
  }
  form{
  width: 300px;
  height: 300px;
  margin: 10px auto;
  }
  form select{
  width: 140px;
  height: 50px;
  text-align: center;
  line-height: 30px;
  font-size: 20px;
  }
 </style>
 <script>
  var x = ["請選擇...","美食","景點","電影"];
  var y = [
  ["請選擇..."],
  ["黃燜雞","油燜大蝦","紅燒肉","東坡肉"],
  ["黃山","泰山","嵩山","華山"],
  ["烈日灼心","逆戰(zhàn)","無間道","黑金"]
  ];
  window.onload = init;
  function init(){
  var chose1 = document.getElementById("chose1");
  var chose2 = document.getElementById("chose2");
  chose1.length = x.length;
  for(var i = 0;i<x.length;i++)
  {
   chose1.options[i].text = x[i];
  }
  var index = 0;
  chose2.length = y[index].length;
  for(var j = 0;j<y[index].length;j++)
  {
   chose2.options[j].text = y[index][j];
  }
  }
  function change(obj){
  var chose2 = document.getElementById("chose2");
  chose2.length = y[obj].length;
  for(var j = 0;j<y[obj].length;j++)
  {
   chose2.options[j].text = y[obj][j];
  }
  }
 </script>
 </head>
 <body>
 <form>
  <select id="chose1" onchange="change(this.selectedIndex)"></select>
  <select id="chose2"></select>
 </form>
 </body>
</html>

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論