能显示天气预报的代码.js,不知如何用,请哪位老师指点一下?谢谢。
文件如下:
------------------------------
百度了一下,找了点别人的方法改进了一下。
获取天气网址:http://www.weather.com.cn/html/weather/101210701.shtml这里是温州天气的,当然其他城市自己搜索一下,换一下ID。
由于是写入cookies记录当天天气,所有需要在站点下浏览。
js代码: var Url=escape("http://m.weather.com.cn/data/101210701.html");
var COOKIE_info = "COOKIE_info";
var date = new Date();
var Hours=24-date.getHours()-1;
var Mins=60-date.getMinutes()-1;
var Secs=60-date.getSeconds();
date.setTime(date.getTime() + (1 * Hours * 60 * 60 * 1000) + (1 * 1 * Mins * 60 * 1000) + (1 * 1 * 1 * Secs * 1000));
var RD_cookie_info= $.cookie(COOKIE_info);
$(function(){
if(RD_cookie_info==null)
{
Getdata(Url);
}
else{
$("#weather").html(RD_cookie_info);
}
}) function Getdata(Url)
{
$.ajax({
type:"GET",
cache: "false",
url: "AjaxGet.asp",
data:"Url="+Url,
dataType: "html",
error: function(){$("#weather").html("读取失败...请刷新重试!");},
success: function(json){
var t = '('+json+')';
var result = eval(t);
var Getinfo="";
Getinfo+=result.weatherinfo.date_y+" ";//年月日
Getinfo+=result.weatherinfo.date+" ";//农历年月日
Getinfo+=result.weatherinfo.week+" ";//星期几
Getinfo+="<br />";//换行
Getinfo+=result.weatherinfo.city;//获取城市名称
Getinfo+=" <img src=\"http://m.weather.com.cn/img/c"+result.weatherinfo.img1+".gif\"/> "//天气图片1
Getinfo+="<img src=\"http://m.weather.com.cn/img/c"+result.weatherinfo.img2+".gif\"/> ";//天气图片2
Getinfo+=result.weatherinfo.weather1+" ";//天气情况
Getinfo+=result.weatherinfo.temp1;//温度
$.cookie(COOKIE_info,Getinfo, { path: '/', expires: date });
$("#weather").html(Getinfo);
}
});
}
文件如下:
------------------------------
百度了一下,找了点别人的方法改进了一下。
获取天气网址:http://www.weather.com.cn/html/weather/101210701.shtml这里是温州天气的,当然其他城市自己搜索一下,换一下ID。
由于是写入cookies记录当天天气,所有需要在站点下浏览。
js代码: var Url=escape("http://m.weather.com.cn/data/101210701.html");
var COOKIE_info = "COOKIE_info";
var date = new Date();
var Hours=24-date.getHours()-1;
var Mins=60-date.getMinutes()-1;
var Secs=60-date.getSeconds();
date.setTime(date.getTime() + (1 * Hours * 60 * 60 * 1000) + (1 * 1 * Mins * 60 * 1000) + (1 * 1 * 1 * Secs * 1000));
var RD_cookie_info= $.cookie(COOKIE_info);
$(function(){
if(RD_cookie_info==null)
{
Getdata(Url);
}
else{
$("#weather").html(RD_cookie_info);
}
}) function Getdata(Url)
{
$.ajax({
type:"GET",
cache: "false",
url: "AjaxGet.asp",
data:"Url="+Url,
dataType: "html",
error: function(){$("#weather").html("读取失败...请刷新重试!");},
success: function(json){
var t = '('+json+')';
var result = eval(t);
var Getinfo="";
Getinfo+=result.weatherinfo.date_y+" ";//年月日
Getinfo+=result.weatherinfo.date+" ";//农历年月日
Getinfo+=result.weatherinfo.week+" ";//星期几
Getinfo+="<br />";//换行
Getinfo+=result.weatherinfo.city;//获取城市名称
Getinfo+=" <img src=\"http://m.weather.com.cn/img/c"+result.weatherinfo.img1+".gif\"/> "//天气图片1
Getinfo+="<img src=\"http://m.weather.com.cn/img/c"+result.weatherinfo.img2+".gif\"/> ";//天气图片2
Getinfo+=result.weatherinfo.weather1+" ";//天气情况
Getinfo+=result.weatherinfo.temp1;//温度
$.cookie(COOKIE_info,Getinfo, { path: '/', expires: date });
$("#weather").html(Getinfo);
}
});
}
解决方案 »
- jQuery大神来看看那,帮忙看下这个ie6,ie7为啥不兼容,该怎么修改
- javascript中的两个问题请教,谢谢
- 自己做的简单的特效(新手)哪位大虾分多的给点我吧--囧!(鼓励哈)
- 给一个元素定义了onmouseover事件和momouseout事件,它在它的内部移动时会触发这两个事件引起异常,寻求解决方案
- 这个函数该怎么修改呢?
- |zyciis| 我的一条判断图片是否存在的JS在FireFox中不能执行 谢谢
- 选择导入哪个JS
- 哪里可以找到关于IE的DOM模型的文档?(如图)
- 怎样使窗口滚动条自动滚到最下方?
- 这是..cnzz统计被黑的节奏?那得有多少人中招?
- 一个技术难题,高手帮帮忙!急需实现
- 三张图片切换的效果
比如 a.aspx
你就在 a.aspx 页面的head里面写
<script type="text/javascript" src="xx.js"></script> // src里的是路径
我想在网页里用(html).非常感谢。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head><title>JS使用</title>
<script type="text/javascript">
var Url=escape("http://m.weather.com.cn/data/101210701.html");
var COOKIE_info = "COOKIE_info";
var date = new Date();
var Hours=24-date.getHours()-1;
var Mins=60-date.getMinutes()-1;
var Secs=60-date.getSeconds();
date.setTime(date.getTime() + (1 * Hours * 60 * 60 * 1000) + (1 * 1 * Mins * 60 * 1000) + (1 * 1 * 1 * Secs * 1000));
var RD_cookie_info= $.cookie(COOKIE_info);
$(function(){
if(RD_cookie_info==null)
{
Getdata(Url);
}
else{
$("#weather").html(RD_cookie_info);
}
}) function Getdata(Url)
{
$.ajax({
type:"GET",
cache: "false",
url: "AjaxGet.asp",
data:"Url="+Url,
dataType: "html",
error: function(){$("#weather").html("读取失败...请刷新重试!");},
success: function(json){
var t = '('+json+')';
var result = eval(t);
var Getinfo="";
Getinfo+=result.weatherinfo.date_y+" ";//年月日
Getinfo+=result.weatherinfo.date+" ";//农历年月日
Getinfo+=result.weatherinfo.week+" ";//星期几
Getinfo+="<br />";//换行
Getinfo+=result.weatherinfo.city;//获取城市名称
Getinfo+=" <img src=\"http://m.weather.com.cn/img/c"+result.weatherinfo.img1+".gif\"/> "//天气图片1
Getinfo+="<img src=\"http://m.weather.com.cn/img/c"+result.weatherinfo.img2+".gif\"/> ";//天气图片2
Getinfo+=result.weatherinfo.weather1+" ";//天气情况
Getinfo+=result.weatherinfo.temp1;//温度
$.cookie(COOKIE_info,Getinfo, { path: '/', expires: date });
$("#weather").html(Getinfo);
}
});
}
</script>
</head><body><div id="content"></div>
</body>
</html>
然后<script type="text/javascript" src="jquery.js"></script>在头部加上这个
<html>
<head>
<title>页面名称</title>
<script type="text/javascript" src="xx.js"></script>
<script type="text/javascript" src="jquery.js"></script>
</head>
<body>
</body>
</html>
src是JS文件路径
上面的“xx”是什么?