zoukankan      html  css  js  c++  java
  • javascript二级省市select联动菜单

    需要用到这种效果,但是看到网上找的写得又太高深,干脆就自动动手了,,哈哈。。。

    先写了个二级的,三级的原理也是一样的啦,不过目前我都没用到它。。。

     打个包给分享给需要的朋友吧,一定要location_cn.js才能用哦。。。

     下载

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <style type="text/css">
    select{width:88px;}
    </style>
    <script type="text/javascript" src="location_cn.js"></script>
    <script type="text/javascript">
    window.onload=function(){
        var oProvince=document.form1.province;
        var oCity=document.form1.city;
        var oBtn=document.getElementById('btn1');
        for(var i=0;i<aProvince.length;i++){
            oProvince.options[i]=new Option(aProvince[i]);
        }
        for(var i=0;i<aCity[0].length;i++){
            oCity.options[i]=new Option(aCity[0][i]);
        }
        
        oProvince.onchange=function(){
            oCity.length=0;
            for(var i=0;i<aCity[this.selectedIndex].length;i++){
                oCity.options[i]=new Option(aCity[this.selectedIndex][i]);
            }
        };
        oBtn.onclick=function(){
            alert('哇哦!您的所在地是:【'+oProvince.options[oProvince.selectedIndex].text+' - '+oCity.options[oCity.selectedIndex].text+'');    
        };
    };
    
    </script>
    </head>
    
    <body>
    <form name="form1">
        <select name="province"></select>
        <select name="city"></select>
        <input type="button" value="提交" id="btn1" />
    </form>
    </body>
    </html>
  • 相关阅读:
    [BZOJ 2821] 作诗
    [P1084] 疫情控制
    [BZOJ 2243] 染色
    Session
    Jinja2 及 render_template 的深度用法
    request机制
    三件套
    初识flask
    mysql大法
    liunx命令大全
  • 原文地址:https://www.cnblogs.com/hejia/p/2950333.html
Copyright © 2011-2022 走看看