0
回答
写了一个地址连动。但是访问不到变量,怎么回事
  (function() {
        var ccc = null;

        window.onload=function() {
            a();
            b();
        }
         function a() {
           ccc=1;
        }

        function b() {
            alert(ccc); //可以弹出1
        }

    })()

 (function(){
           var areaDoc= null;
            window.onload=init;

            function init() {
                getData(createXMLHttpRequest());
              //  alert(areaDoc.getElementsByTagName("province"));
                loadProvince();
                var province = document.getElementById("province");
                var city = document.getElementById("city");
                var country = document.getElementById("country");

                province.onchange=getProvince;
                city.onchange=getCity;
                country.onchange=getTown;


            }


            //第一个select载入数据
            function loadProvince() {
  -------          这里为啥就弹出null呢-----------------------------------
                alert(areaDoc.getElementsByTagName("province"));
             //  var pns = areaDoc.getElementsByTagName("province");
              //  insertOption(pns,"province")
            }

            //获取xml数据从后台
            function getData(obj) {
                obj.open("GET","Area.xml",true);
                obj.onreadystatechange=function() {
                    if(obj.readyState==4 && obj.status==200) {
                        areaDoc="<a>123</a>"
                       // alert(areaDoc.getElementsByTagName("province"));
                    }
                }
                obj.send();
            }
            //创建XMLHttpRequest对象
            function createXMLHttpRequest() {
                if(window.XMLHttpRequest) {
                    return new XMLHttpRequest();
                } else if(window.ActiveXObject) {
                    return new ActiveXObject("Microsoft.XMLHTTP");
                }else{
                    alert("你使用的浏览器不支持XMLHttpRequest,请换一个浏览器再试!");
                    return null;
                }

            }





<无标签>
举报
顶部