json

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>

<!--
    city  -> 插入option 中
    div 中{

        date_y -- 》h1
        p 中{
            week
            temp1
            weather1
            wind1
            index
        }
    }
 点击option时,切换div 不同城市的天气信息

-->
<body>
<div id="box">
    <select name="" id="sel">
        <option value="-1">-请选择-</option>
    </select>
</div>
</body>
<script type="text/javascript">




        var jsonDat = {
            "weatherinfo": [
                {
                    "city": "杭州",
                    "city_en": "hangzhou",
                    "date_y": "2013年11月4日",
                    "date": "",
                    "week": "星期一",
                    "fchh": "08",
                    "cityid": "101210101",
                    "temp1": "21℃~13℃",
                    "temp2": "21℃~13℃",
                    "temp3": "23℃~14℃",
                    "temp4": "23℃~17℃",
                    "temp5": "25℃~17℃",
                    "temp6": "27℃~14℃",
                    "tempF1": "69.8℉~55.4℉",
                    "tempF2": "69.8℉~55.4℉",
                    "tempF3": "73.4℉~57.2℉",
                    "tempF4": "73.4℉~62.6℉",
                    "tempF5": "77℉~62.6℉",
                    "tempF6": "80.6℉~57.2℉",
                    "weather1": "多云",
                    "weather2": "多云",
                    "weather3": "多云",
                    "weather4": "多云",
                    "weather5": "多云转阴",
                    "weather6": "阴转小雨",
                    "img1": "1",
                    "img2": "99",
                    "img3": "1",
                    "img4": "99",
                    "img5": "1",
                    "img6": "99",
                    "img7": "1",
                    "img8": "99",
                    "img9": "1",
                    "img10": "2",
                    "img11": "2",
                    "img12": "7",
                    "img_single": "1",
                    "img_title1": "多云",
                    "img_title2": "多云",
                    "img_title3": "多云",
                    "img_title4": "多云",
                    "img_title5": "多云",
                    "img_title6": "多云",
                    "img_title7": "多云",
                    "img_title8": "多云",
                    "img_title9": "多云",
                    "img_title10": "阴",
                    "img_title11": "阴",
                    "img_title12": "小雨",
                    "img_title_single": "多云",
                    "wind1": "北风小于5级",
                    "wind2": "东风小于3级",
                    "wind3": "北风小于3级",
                    "wind4": "东风小于3级",
                    "wind5": "东南风小于3级",
                    "wind6": "西北风小于3级",
                    "fx1": "北风",
                    "fx2": "北风",
                    "fl1": "小于3级",
                    "fl2": "小于3级",
                    "fl3": "小于3级",
                    "fl4": "小于3级",
                    "fl5": "小于3级",
                    "fl6": "小于3级",
                    "index": "较舒适",
                    "index_d": "建议着薄外套、开衫牛仔衫裤等服装。年老体弱者应适当添加衣物,宜着夹克衫、薄毛衣等。",
                    "index48": "较舒适",
                    "index48_d": "建议着薄外套、开衫牛仔衫裤等服装。年老体弱者应适当添加衣物,宜着夹克衫、薄毛衣等。",
                    "index_uv": "弱",
                    "index48_uv": "弱",
                    "index_xc": "适宜",
                    "index_tr": "适宜",
                    "index_co": "舒适",
                    "st1": "21",
                    "st2": "13",
                    "st3": "21",
                    "st4": "13",
                    "st5": "23",
                    "st6": "14",
                    "index_cl": "适宜",
                    "index_ls": "适宜",
                    "index_ag": "极不易发"
                },
                {
                    "city": "北京",
                    "city_en": "beijing",
                    "date_y": "2014年11月4日",
                    "date": "",
                    "week": "星期二",
                    "fchh": "08",
                    "cityid": "101210101",
                    "temp1": "21℃~33℃",
                    "temp2": "21℃~13℃",
                    "temp3": "23℃~14℃",
                    "temp4": "23℃~17℃",
                    "temp5": "25℃~17℃",
                    "temp6": "27℃~14℃",
                    "tempF1": "69.8℉~55.4℉",
                    "tempF2": "69.8℉~55.4℉",
                    "tempF3": "73.4℉~57.2℉",
                    "tempF4": "73.4℉~62.6℉",
                    "tempF5": "77℉~62.6℉",
                    "tempF6": "80.6℉~57.2℉",
                    "weather1": "多云转阴",
                    "weather2": "多云",
                    "weather3": "多云",
                    "weather4": "多云",
                    "weather5": "多云转阴",
                    "weather6": "阴转小雨",
                    "img1": "1",
                    "img2": "99",
                    "img3": "1",
                    "img4": "99",
                    "img5": "1",
                    "img6": "99",
                    "img7": "1",
                    "img8": "99",
                    "img9": "1",
                    "img10": "2",
                    "img11": "2",
                    "img12": "7",
                    "img_single": "1",
                    "img_title1": "多云",
                    "img_title2": "多云",
                    "img_title3": "多云",
                    "img_title4": "多云",
                    "img_title5": "多云",
                    "img_title6": "多云",
                    "img_title7": "多云",
                    "img_title8": "多云",
                    "img_title9": "多云",
                    "img_title10": "阴",
                    "img_title11": "阴",
                    "img_title12": "小雨",
                    "img_title_single": "多云",
                    "wind1": "北风小于6级",
                    "wind2": "东风小于3级",
                    "wind3": "北风小于3级",
                    "wind4": "东风小于3级",
                    "wind5": "东南风小于3级",
                    "wind6": "西北风小于3级",
                    "fx1": "北风",
                    "fx2": "北风",
                    "fl1": "小于3级",
                    "fl2": "小于3级",
                    "fl3": "小于3级",
                    "fl4": "小于3级",
                    "fl5": "小于3级",
                    "fl6": "小于3级",
                    "index": "较舒适",
                    "index_d": "建议着薄外套、开衫牛仔衫裤等服装。年老体弱者应适当添加衣物,宜着夹克衫、薄毛衣等。",
                    "index48": "较舒适",
                    "index48_d": "建议着薄外套、开衫牛仔衫裤等服装。年老体弱者应适当添加衣物,宜着夹克衫、薄毛衣等。",
                    "index_uv": "弱",
                    "index48_uv": "弱",
                    "index_xc": "适宜",
                    "index_tr": "适宜",
                    "index_co": "舒适",
                    "st1": "21",
                    "st2": "13",
                    "st3": "21",
                    "st4": "13",
                    "st5": "23",
                    "st6": "14",
                    "index_cl": "适宜",
                    "index_ls": "适宜",
                    "index_ag": "极不易发"
                },
                {
                    "city": "上海",
                    "city_en": "shanghai",
                    "date_y": "2015年11月4日",
                    "date": "",
                    "week": "星期三",
                    "fchh": "08",
                    "cityid": "101210101",
                    "temp1": "31℃~43℃",
                    "temp2": "21℃~13℃",
                    "temp3": "23℃~14℃",
                    "temp4": "23℃~17℃",
                    "temp5": "25℃~17℃",
                    "temp6": "27℃~14℃",
                    "tempF1": "69.8℉~55.4℉",
                    "tempF2": "69.8℉~55.4℉",
                    "tempF3": "73.4℉~57.2℉",
                    "tempF4": "73.4℉~62.6℉",
                    "tempF5": "77℉~62.6℉",
                    "tempF6": "80.6℉~57.2℉",
                    "weather1": "多云",
                    "weather2": "多云",
                    "weather3": "多云",
                    "weather4": "多云",
                    "weather5": "多云转阴",
                    "weather6": "阴转小雨",
                    "img1": "1",
                    "img2": "99",
                    "img3": "1",
                    "img4": "99",
                    "img5": "1",
                    "img6": "99",
                    "img7": "1",
                    "img8": "99",
                    "img9": "1",
                    "img10": "2",
                    "img11": "2",
                    "img12": "7",
                    "img_single": "1",
                    "img_title1": "多云",
                    "img_title2": "多云",
                    "img_title3": "多云",
                    "img_title4": "多云",
                    "img_title5": "多云",
                    "img_title6": "多云",
                    "img_title7": "多云",
                    "img_title8": "多云",
                    "img_title9": "多云",
                    "img_title10": "阴",
                    "img_title11": "阴",
                    "img_title12": "小雨",
                    "img_title_single": "多云",
                    "wind1": "北风小于8级",
                    "wind2": "东风小于3级",
                    "wind3": "北风小于3级",
                    "wind4": "东风小于3级",
                    "wind5": "东南风小于3级",
                    "wind6": "西北风小于3级",
                    "fx1": "北风",
                    "fx2": "北风",
                    "fl1": "小于3级",
                    "fl2": "小于3级",
                    "fl3": "小于3级",
                    "fl4": "小于3级",
                    "fl5": "小于3级",
                    "fl6": "小于3级",
                    "index": "较舒适",
                    "index_d": "建议着薄外套、开衫牛仔衫裤等服装。年老体弱者应适当添加衣物,宜着夹克衫、薄毛衣等。",
                    "index48": "较舒适",
                    "index48_d": "建议着薄外套、开衫牛仔衫裤等服装。年老体弱者应适当添加衣物,宜着夹克衫、薄毛衣等。",
                    "index_uv": "弱",
                    "index48_uv": "弱",
                    "index_xc": "适宜",
                    "index_tr": "适宜",
                    "index_co": "舒适",
                    "st1": "21",
                    "st2": "13",
                    "st3": "21",
                    "st4": "13",
                    "st5": "23",
                    "st6": "14",
                    "index_cl": "适宜",
                    "index_ls": "适宜",
                    "index_ag": "极不易发"
                },
                {
                    "city": "深圳",
                    "city_en": "shenzhen",
                    "date_y": "2016年11月4日",
                    "date": "",
                    "week": "星期四",
                    "fchh": "08",
                    "cityid": "101210101",
                    "temp1": "121℃~131℃",
                    "temp2": "21℃~13℃",
                    "temp3": "23℃~14℃",
                    "temp4": "23℃~17℃",
                    "temp5": "25℃~17℃",
                    "temp6": "27℃~14℃",
                    "tempF1": "69.8℉~55.4℉",
                    "tempF2": "69.8℉~55.4℉",
                    "tempF3": "73.4℉~57.2℉",
                    "tempF4": "73.4℉~62.6℉",
                    "tempF5": "77℉~62.6℉",
                    "tempF6": "80.6℉~57.2℉",
                    "weather1": "阴转小雨",
                    "weather2": "多云",
                    "weather3": "多云",
                    "weather4": "多云",
                    "weather5": "多云转阴",
                    "weather6": "阴转小雨",
                    "img1": "1",
                    "img2": "99",
                    "img3": "1",
                    "img4": "99",
                    "img5": "1",
                    "img6": "99",
                    "img7": "1",
                    "img8": "99",
                    "img9": "1",
                    "img10": "2",
                    "img11": "2",
                    "img12": "7",
                    "img_single": "1",
                    "img_title1": "多云",
                    "img_title2": "多云",
                    "img_title3": "多云",
                    "img_title4": "多云",
                    "img_title5": "多云",
                    "img_title6": "多云",
                    "img_title7": "多云",
                    "img_title8": "多云",
                    "img_title9": "多云",
                    "img_title10": "阴",
                    "img_title11": "阴",
                    "img_title12": "小雨",
                    "img_title_single": "多云",
                    "wind1": "北风小于9级",
                    "wind2": "东风小于3级",
                    "wind3": "北风小于3级",
                    "wind4": "东风小于3级",
                    "wind5": "东南风小于3级",
                    "wind6": "西北风小于3级",
                    "fx1": "北风",
                    "fx2": "北风",
                    "fl1": "小于3级",
                    "fl2": "小于3级",
                    "fl3": "小于3级",
                    "fl4": "小于3级",
                    "fl5": "小于3级",
                    "fl6": "小于3级",
                    "index": "较舒适",
                    "index_d": "建议着薄外套、开衫牛仔衫裤等服装。年老体弱者应适当添加衣物,宜着夹克衫、薄毛衣等。",
                    "index48": "较舒适",
                    "index48_d": "建议着薄外套、开衫牛仔衫裤等服装。年老体弱者应适当添加衣物,宜着夹克衫、薄毛衣等。",
                    "index_uv": "弱",
                    "index48_uv": "弱",
                    "index_xc": "适宜",
                    "index_tr": "适宜",
                    "index_co": "舒适",
                    "st1": "21",
                    "st2": "13",
                    "st3": "21",
                    "st4": "13",
                    "st5": "23",
                    "st6": "14",
                    "index_cl": "适宜",
                    "index_ls": "适宜",
                    "index_ag": "极不易发"
                }
            ]
        };
        var _sel = document.getElementById('sel');
        var _box = document.getElementById('box');

        //城市
        for (var i = 0; i < jsonDat.weatherinfo.length; i++) {
            var _option = document.createElement("option");
            _option.setAttribute("value", i);
            _sel.appendChild(_option);
            _option.innerText = jsonDat.weatherinfo[i].city;
        }
        //创建盒子div
        var _div = document.createElement("div");
//       _div.setAttribute("class", "div1");
        _box.appendChild(_div);

        //创建h1并插入div
       var H1= document.createElement("h1");
        _div.appendChild(H1);

        //创建5个 p标签
        for(var j=0;j<5;j++){
            var P=document.createElement('p');
            _div.appendChild(P);
        }



    _sel.οnchange=function(){
        if(this.value==-1){
            _div.style.display="none";
        }
        else{
            _div.style.display="block";
            for(var i = 0; i < jsonDat.weatherinfo.length; i++){
                if(this.value==i){
                    _div.children[0].innerHTML=jsonDat.weatherinfo[i].date_y;
                    _div.children[1].innerHTML=jsonDat.weatherinfo[i].week;
                    _div.children[2].innerHTML=jsonDat.weatherinfo[i].temp1;
                    _div.children[3].innerHTML=jsonDat.weatherinfo[i].weather1;
                    _div.children[4].innerHTML=jsonDat.weatherinfo[i].wind1;
                    _div.children[5].innerHTML=jsonDat.weatherinfo[i].index;
                }
            }
        }
    }




</script>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值