用XML实现国家、省的动态关联

<script>
<!--
/----------无垠网域-------------------/
/----------嘻哈呵嘿-------------------/
    /* 切换国家对应省所用的函数 */
    function populateSheng()
    {
        pri = main.country.options(main.country.selectedIndex).value;
        var oXMLDoc = new ActiveXObject('MSXML');
        sURL = 'http://210.192.103.40/HAS_Client/UserReg/change_place_dshxml.asp?pri=' + pri;
        
        oXMLDoc.url = sURL;
        var oRoot=oXMLDoc.root;
        if(oRoot.children != null)
        {   
            //删除省选择框中的所有选项
            for(var i=main.province.options.length-1;i>=0;--i)
            {
                main.province.options.remove(i)
            }
            var i=0;
            //往省选择框中增加选项
            while (i<oRoot.children.length)
            {
                oval = oRoot.children.item(i);
                i=i+1;
                oname = oRoot.children.item(i);
                sval = oval.text;
                sname = oname.text;
                var oOption = document.createElement('OPTION');
                oOption.text = sname;
                oOption.value = sval;
                main.province.options.add(oOption);
                i=i+1;
            }
            
            //删除市选择框中的所有选项
            for(var i=main.city.options.length-1;i>=0;--i)
            {
                main.city.options.remove(i)
            }
            //往市选择框中增加选项
            var oOption1 = document.createElement('OPTION');
            oOption1.text = "请选择";
            oOption1.value = 0;
            main.city.options.add(oOption1);
        }
    }

    /* 切换省对应市所用的函数 */
    function populateCity()
    {
        pri = main.province.options(main.province.selectedIndex).value;
        var oXMLDoc = new ActiveXObject('MSXML');    
        sURL = 'http://210.192.103.40/HAS_Client/UserReg/change_place_dchxml.asp?pri=' + pri;
        
        oXMLDoc.url = sURL;
        var oRoot=oXMLDoc.root;
        if(oRoot.children != null)
        {   
            //删除市选择框中的所有选项
            for(var i=main.city.options.length-1;i>=0;--i)
            {
                main.city.options.remove(i)
            }
            var i=0;
            //往市选择框中增加选项
            while (i<oRoot.children.length)
            {
                oval = oRoot.children.item(i);
                i=i+1;
                oname = oRoot.children.item(i);
                sval = oval.text;
                sname = oname.text;
                var oOption = document.createElement('OPTION');
                oOption.text = sname;
                oOption.value = sval;
                main.city.options.add(oOption);
                i=i+1;
            }
        }
    }
//-->
</script>

<body>
<form name="main" method="post">
     国家或地区:<select id=country name=country size=1 onchange=populateSheng()>
                      <option selected value="">请选择</option>
                      <option value=中国>中国</option>
                      <option value=中国香港>中国香港</option>
                      <option value=中国台湾>中国台湾</option>

                      <option value=中国澳门>中国澳门</option>
                      <option value=其它>其它</option>
      </select>

     省、直辖市:<select id=province name=province size=1 onchange=populateCity()>
                      <option selected value=0>请选择</option>
     </select>

     省辖各地区:<select name="city">
                      <option value=0>请选择</option>
     </select>
</form>

Copy过去就可以用啦 。。呵呵。。盗用了万网的东东。。不过NS不支持这个哦。
如果出现拒绝访问的错误,那就只好自己写程序输出xml啦

300*300
  • 没有相关文章
  • 没有评论
 文章首页关于迷茫时代关于我写意人生
版权所有:迷茫时代 All rights reserved   
执行时间:0.00506 秒