zoukankan      html  css  js  c++  java
  • 三级联动下拉框效果

     1 <!DOCTYPE html>
     2 <html xmlns="http://www.w3.org/1999/xhtml">
     3 <head>
     4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
     5     <title>三级联动菜单</title>
     6     <link href="css/demo.css" rel="stylesheet" />
     7     <script src="js/jquery-1.10.2.min.js"></script>
     8     <script src="js/demo.js"></script>
     9 </head>
    10 <body>
    11     <select id="selProvince">
    12         <option>---请选择---</option>
    13     </select>
    14     <select id="selCity">
    15         <option>---请选择---</option>
    16     </select>
    17     <select id="selCountry">
    18         <option>---请选择---</option>
    19     </select>
    20 </body>
    21 </html>
     1 /// <reference path="jquery-1.10.2.min.js" />
     2 var aProvince = ["河北省", "山西省", "湖北省"];
     3 var aCity = [["石家庄市", "张家口市", "承德市", "秦皇岛市"], ["太原市", "朔州市", "大同市", "阳泉市"], ["武汉市", "孝感市", "宜昌市", "襄阳市"]];
     4 var aCountry = [[["无极县", "赵县", "栾城县"], ["沽源县", "尚义县", "阳原县"], ["平泉县", "滦平县", "隆化县"], ["抚宁县", "卢龙县", "昌黎县"]], [["清徐县", "阳曲县", "娄烦县"], ["山阴县", "应县", "右玉县"], ["左云县", "阳高县", "天镇县"], ["盂县", "平定县", "矿区"]],
     5 [["武昌区", "洪山区", "东湖新区"], ["云梦县", "大悟县", "应城市"], ["秭归县", "远安县", "枝江市"], ["枣阳市", "老河口市", "谷城县"]]];
     6 var num1 = 0;
     7 var num2 = 0;
     8 $(function () {
     9     for (var i = 0; i < aProvince.length; i++) {
    10         $("#selProvince").append("<option>" + aProvince[i] + "</option>");
    11     }
    12 
    13     $("#selProvince").change(function () {
    14         $("#selCity").children("option").not(":eq(0)").remove();
    15         $("#selCountry").children("option").not(":eq(0)").remove();
    16         num1 = $(this).children("option:selected").index();
    17         if (num1 > 0) {
    18             var aC = aCity[num1 - 1];
    19             for (var i = 0; i < aC.length; i++) {
    20                 $("#selCity").append("<option>" + aC[i] + "</option>");
    21             }
    22         }
    23     });
    24 
    25     $("#selCity").change(function () {
    26         $("#selCountry").children("option").not(":eq(0)").remove();
    27         num2 = $(this).children("option:selected").index();
    28         if (num2 > 0) {
    29             var aC = aCountry[num1 - 1][num2 - 1];
    30             for (var i = 0; i < aC.length; i++) {
    31                 $("#selCountry").append("<option>" + aC[i] + "</option>");
    32             }
    33         }
    34     });
    35 
    36 });

  • 相关阅读:
    matplotlib: ylabel on the right
    ssh 密钥管理
    [转]Linux下创建静态、动态库
    Perl命令行应用介绍
    zz:快速编辑Shell命令行
    zz Makefile学习教程: 跟我一起写 Makefile
    Eureka服务剔除下线
    数据结构可视化
    aeImageResize jQuery图片等比缩放调整插件
    最全的CSS浏览器兼容问题整理(IE6.0、IE7.0 与 FireFox)
  • 原文地址:https://www.cnblogs.com/snow52132/p/7238604.html
Copyright © 2011-2022 走看看