求javascript高手帮忙,解释一段天气预报的代码,最好是每一句的意思

[复制链接]
查看11 | 回复2 | 2011-6-26 04:10:40 | 显示全部楼层 |阅读模式
varWeaherDataList;
varxhr;
functioninit(){
        choose();
}//初始化变量
functiongetData(cityName){
        xhr=newXMLHttpRequest();
        varurl=\"<ahref=\"http://www.polyvi.com.cn:8090/weather/servlet/cityservice?city=\"target=\"_blank\">http://www.polyvi.com.cn:8090/weather/servlet/cityservice?city=</a>\";//后台服务器地址
        url=cityName;
        xhr.open(\"GET\",url,true);
        xhr.onreadystatechange=forCallback;
        xhr.send(null);
}//联网获取服务器数据
functionforCallback(){
        if(xhr.readyState==4||xhr.readyState==\"complete\"){
                varstring=xhr.responseText;
                if(string==\"0\"){
                        alert(\"查询失败。。。\");
                        return;
                }else{
                        //WeaherDataList=string;
                        eval(\"WeaherDataList\"\"=\"string);
                        fillData();
                        return;
                }
        }
}//获取数据异步回调函数
functionfillData(){
        window.prepareForTransition();
        $(\"cityname\").firstChild.data=WeaherDataList.city;
        $(\"thermometer\").firstChild.data=WeaherDataList.temperature;
        $(\"weather\").firstChild.data=WeaherDataList.description;
        $(\"logo\").src=\"img/\"WeaherDataList.wcode\".png\";
        window.performTransition();
}//显示查询结果的数据

functionfillNoData(){
        window.prepareForTransition();
        $(\"city\").firstChild.data=cityName;
        $(\"thermometer\").firstChild.data=\"failed\";
        $(\"weather\").firstChild.data=\"查询失败\";
        window.performTransition();
}

functionchoose(){
        window.prepareForTransition();
        $(\"showBar\").style.display=\"none\";
        $(\"chooseBar\").style.display=\"block\";
        window.document.body.focus();
        window.performTransition();
}

functionsubmit(){
        window.prepareForTransition();
        $(\"chooseBar\").style.display=\"none\";
        $(\"showBar\").style.display=\"block\";
        window.document.body.focus();
        varcityName=$(\"cityName\").value;
        $(\"city\").firstChild.data=\"请等待\";
        $(\"thermometer\").firstChild.data=\"查询中\";
        $(\"weather\").firstChild.data=\"查询中\";
        window.performTransition();
        getData(cityName);
}//发起查询的请求

function$(id){
        returndocument.getElementById(id);
}//通过id获取dom对象
回复

使用道具 举报

千问 | 2011-6-26 04:10:40 | 显示全部楼层
varWeaherDataList;
varxhr;
functioninit(){
        choose();//调用函数开头
}//初始化变量
functiongetData(cityName){
        xhr=newXMLHttpRequest();
        varurl=\"<ahref=\"http://www.polyvi.com.cn:8090/weather/servlet/cityservice?city=\"target=\"_blank\">http://www.polyvi.com.cn:8090/weather/servlet/cityservice?city=</a>\";//后台服务器地址
        url=cityName;
        xhr.open(\"GET\",url,true);
        xhr.onreadystatechange=forCallback;
        xhr.send(null);//从服务器取得正确信息,得到时间等
}//联网获取服务器数据
functionforCallback(){
        if(xhr.readyState==4||xhr.readyState==\"complete\"){
                varstring=xhr.responseText;
                if(string==\"0\"){
                        alert(\"查询失败。。。\");
                        return;//发生非法请求或则服务器维护时出现错误,不能从服务器取得信息。
                }else{
                        //WeaherDataList=string;
                        eval(\"WeaherDataList\"\"=\"string);//获取天气列表数据
                        fillData();
                        return;//返回
                }
        }
}//获取数据异步回调函数
functionfillData(){
        window.prepareForTransition();
        $(\"cityname\").firstChild.data=WeaherDataList.city;
        $(\"thermometer\").firstChild.data=WeaherDataList.temperature;
        $(\"weather\").firstChild.data=WeaherDataList.description;
        $(\"logo\").src=\"img/\"WeaherDataList.wcode\".png\";
        window.performTransition();
}//与服务器对接,获得数据,操作合法给予查看,请求成功

functionfillNoData(){
        window.prepareForTransition();
        $(\"city\").firstChild.data=cityName;
        $(\"thermometer\").firstChild.data=\"failed\";
        $(\"weather\").firstChild.data=\"查询失败\";
        window.performTransition();
}//服务器响应超时,导致失败,给予弹窗“查询失败”

functionchoose(){
        window.prepareForTransition();
        $(\"showBar\").style.display=\"none\";
        $(\"chooseBar\").style.display=\"block\";
        window.document.body.focus();
        window.performTransition();
}//调用本地函数进行翻译

functionsubmit(){
        window.prepareForTransition();
        $(\"chooseBar\").style.display=\"none\";
        $(\"showBar\").style.display=\"block\";
        window.document.body.focus();
        varcityName=$(\"cityName\").value;
        $(\"city\").firstChild.data=\"请等待\";
        $(\"thermometer\").firstChild.data=\"查询中\";
        $(\"weather\").firstChild.data=\"查询中\";
        window.performTransition();
        getData(cityName);
}//发起查询的请求

function$(id){
        returndocument.getElementById(id);
}//通过id获取dom对象,就是对信息的取回结束,ok
睬我阿、!!!!!不懂QQ:767999058
回复

使用道具 举报

千问 | 2011-6-26 04:10:40 | 显示全部楼层
这个我主要是想搞懂每句代码的意思,答辩的时候怕被问到,我不懂,大哥你要懂请帮忙一下
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行