<center> <input type="text" id="city"/> <input type="button" value="查询" id="sub"/> <div id="box" style="display: none"> <table border="1"> <th>日期</th> <th>星期</th> <th>城市</th> <th>图片</th> <th>温度</th> <th>天气</th> <th>风向</th> <th>风力</th> <tbody id="tianqi"></tbody> </table> </div> </center>
$(function(){ $("#sub").click(function(){ var city=$("#city").val(); $.ajax({ url:"http://api.k780.com:88/?app=weather.future&weaid="+city+"&&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json&jsoncallback=data", type:'GET', dataType:'jsonp', jsonp:'callback', jsonpCallback:'data', success:function(result){ var re=result.result; var str=""; for(i in re){ str+="<tr>"; str+="<td>"+result.result[i].days+"</td>"; str+="<td>"+result.result[i].week+"</td>"; str+="<td>"+result.result[i].citynm+"</td>"; str+="<td><img src="+result.result[i].weather_icon+"></td>"; str+="<td>"+result.result[i].temperature+"</td>"; str+="<td>"+result.result[i].weather+"</td>"; str+="<td>"+result.result[i].wind+"</td>"; str+="<td>"+result.result[i].winp+"</td>"; str+="</tr>"; } $("#box").show(); $("#tianqi").html(str); } }) }) })