欢迎使用CSDN-markdown编辑器

来源:互联网 发布:linux双系统引导修复 编辑:程序博客网 时间:2024/06/08 13:16

JSON相关

jQuery函数样式 $(document).ready();
每个对象属性和属性值的组合就是我们经常听到的”键值对(key-value pairs)”。
每个对象都包含了一个以imageLink为键(key),以猫的图片的url为值(value)的键值对。
当我们在遍历这些对象时,我们用imageLink的属性来显示img元素的图片。

//获取当前经纬度  if(navigator.geolocation)  {    {      $("#data").html("latitude:"+position.coords.latitude+"<br>longtitude:"+position.coords.longtitude);    });  }$("#getMessage").on(  "click",function(){ //通过jQuery来绑定点击事件    $(.massage).html("change getMassage's massage")}  );//点击改变getMassage's massage    $.getJSON("/json/cats.json",function(json){        $(".message").html(JSON.stringify(json));        //点击按钮,getMassage's massage替换成此从FreeCodeCam的猫图API中(应用程序接口)获得的原始JSON数据。        var html="";        json.forEach(function(val)        {            var keys=Object.keys(val);            html+="<div class="cat">";            html+=" img src=" "+val.imgLink+" " ";            //用imageLink的属性来显示img元素的图片。            json=json.filter(function(val){                return (val.id!==1);            });            keys.forEach(function(key)            {                html+="<b>"+key+"</b>:"+val[key]+"<br>";            });            html+="</div><r>";        });        $(".message").html(html);      });});