原生js实现二级联动菜单
网络编程 2021-07-04 15:02www.168986.cn编程入门
这篇文章主要为大家详细介绍了原生js实现二级联动菜单,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了js二级联动菜单的具体代码,供大家参考,具体内容如下
效果如下:
代码如下:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>二级联动菜单</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 = [ ["请选择..."], ["黄焖鸡","油焖大虾","红烧肉","东坡肉"], ["黄山","泰山","嵩山","华山"], ["烈日灼心","逆战","无间道","黑金"] ]; 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>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持狼蚁SEO。
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程