代码为:

$.getScript('http://int.dpool.sina.com/iplookup/iplookup.php?format=js',function(_result){

if(remote_ip_info.ret=='1'){

$.ajax({

type:"GET",

url:"http://wthrcdn.etouch.cn/weather_mini?city="+remote_ip_info.city,

data:'',

success:function(msg){

console.log(msg);

}

});

}

});

msg为一个字符串,里面包含了城市,5天的天气预报等信息。如果需要在页面进行显示,则在页面获取元素后,通过html()来进行设置内容。msg需要先通过eval()方法或者JSON.parse()方法来转换为JSON对象。然后对msg.data.*获取需要的属性值。如我设置了一个id为a的div,使里面显示天气内容:

var r=eval('('+msg+')');    //也可以使用JSON.parse(msg);
$('#a').html(r.data.city+"   "+r.data.forecast[0].date+r.data.forecast[0].fengli+r.data.forecast[0].high+r.data.forecast[0].low+r.data.forecast[0].type);
console.log(r);

通过jquery获取天气的方法的更多相关文章

  1. JQuery获取元素的方法总结

    JQuery获取元素的方法总结 一.说明   获取元素的方法分为两种:jQuery选择器.jQuery遍历函数. 做个总结,巩固下知识. 二.获取本身 1.只需要一种jQuery选择器   选择器 实 ...

  2. JavaScript&jQuery获取url参数方法

    JavaScript&jQuery获取url参数方法 function getUrlParam(name){ var reg = new RegExp("(^|&)" ...

  3. 【鬼脸原创】JQuery获取元素的方法总结

    目录 一.说明 二.获取本身 三.获取同级元素 四.获取父级元素 五.获取子级元素 一.说明   获取元素的方法分为两种:jQuery选择器.jQuery遍历函数. 做个总结,巩固下知识. 二.获取本 ...

  4. js(jQuery)获取时间的方法及常用时间类搜集

    获取时间的方法及常用时间类都是大家经常使用的,在本文为大家整理了一些,个人感觉还比较全,感兴趣的朋友可以收集下   复制代码代码如下: $(function(){ var mydate = new D ...

  5. 对比jquery获取属性的方法props、attr、data

    1.attr,prop 对于HTML元素本身就带有的固有属性,在处理时,使用prop方法.对于自定义的属性是取不到的: 对于HTML元素我们自己自定义的DOM属性,在处理时,使用attr方法. 2.a ...

  6. js(jQuery)获取时间的方法及常用时间类

    获取JavaScript 的时间使用内置的Date函数完成 var mydate = new Date();mydate.getYear(); //获取当前年份(2位)mydate.getFullYe ...

  7. 转-- js(jQuery)获取时间的方法及常用时间类

    来自:http://blog.csdn.NET/liujun198773/article/details/7554628  感谢 $(function(){ var mydate = new Date ...

  8. jQuery获取各种位置方法

    一.获取窗口的宽高 1.获取流览器显示区域的高度 : $(window).height(); 2.获取流览器显示区域的宽度 : $(window).width(); 3.获取文档流的高度 : $(do ...

  9. jquery 获取url 参数方法 以及 解决url中文问题

    //jQuery 动态给a 标签赋值 跳转 新的页面打开. /* <a class="btn btn-success" id="test" target= ...

随机推荐

  1. WINDOWS SERVER 2008 RD服务器搭建

    RD服务器详细名称为:RemoteDesktop Server 远程桌面服务器.但微软觉得这名字很怪诞,所以中文名用:终端服务器来代替这个叫法:TerminalServiceServer 在介绍搭建之 ...

  2. 后台进程管理supervisor

    一.安装 该工具是python的一个软件包,需要安装python及其python-setuptools 二.安装完后会在python的bin目录下找到对应的命令文件 三.安装supervisor为服务 ...

  3. Javascript,颜色渐变效果的处理

    在搭建博主博客的时候,寻思着做一些效果,看到菜单,就想是不是可以做一下颜色的渐变,增加一点动态的感觉.有个jquery的插件,效果相当不错,不过博主还是打算自立更生写一下,看看能不能实现. 下面就是博 ...

  4. Transferring Files to Your Instance with WinSCP

    WinSCP is a GUI-based file manager for Windows that allows you to upload and transfer files to a rem ...

  5. 基于FormsAuthentication的用户、角色身份认证

    一般情况下,在我们做访问权限管理的时候,会把用户的正确登录后的基本信息保存在Session中,以后用户每次请求页面或接口数据的时候,拿到 Session中存储的用户基本信息,查看比较他有没有登录和能否 ...

  6. Error of "Please Check for Sufficient Write File Permissions"

    The error message “Please check for sufficient write file permissions” is generated by the Web-based ...

  7. NSInternalInconsistencyException

    2016-09-10 12:48:13.281 Friend[92304:1843372] *** Terminating app due to uncaught exception 'NSInter ...

  8. NGINX、PHP-FPM开机自动启动

    NGINX SHELL脚本   放到/etc/init.d/下取名nginx #!/bin/sh # # nginx - this script starts and stops the nginx ...

  9. windows update一直卡住:“正在此计算机上搜索更新”

    参考:http://blog.163.com/smile_big/blog/static/35710579201611875333164/ 解决办法: 管理员运行cmd,输入以下命令 net stop ...

  10. Android Studio: Failed to sync Gradle project 'xxx' Error:Unable to start the daemon process: could not reserve enough space for object heap.

    创建项目的时候报错: Failed to sync Gradle project 'xxx' Error:Unable to start the daemon process: could not r ...