javascript学习(2)

1._proto_属性
每个对象都有一个内部属性_proto_,指向此对象的原型对象。通过这个内部属性,可以从实例对象中读取原型对象的属性。但是不是标准用法。

var a = {x:1}
var b = (_proto_:a)
b.x
//1

2.判断对象是否具有某个属性,使用hasOwnProperty方法。仅能判断对象本身的,继承的不能判断出来,返回false.
Date.hasOwnProperty('length');

3.jQuery解析json数据
下面引用的是官方API对$.getJSON()的说明:
jQuery.getJSON( url, [data,] [success(data, textStatus, jqXHR)] )
urlA string containing the URL to which the request is sent.
dataA map or string that is sent to the server with the request.
success(data, textStatus, jqXHR)A callback function that is executed if the request succeeds.
回调函数中接受三个参数,第一个书返回的数据,第二个是状态,第三个是jQuery的XMLHttpRequest,我们只使用到第一个参数。
$.each()是用来在回调函数中解析JSON数据的方法,下面是官方文档:
jQuery.each( collection, callback(indexInArray, valueOfElement) )
collectionThe object or array to iterate over.
callback(indexInArray, valueOfElement)The function that will be executed on every object.
$.each()方法接受两个参数,第一个是需要遍历的对象集合(JSON对象集合),第二个是用来遍历的方法,这个方法又接受两个参数,第一个是遍历的index,第二个是当前遍历的值
$.each(collection, callback(indexInArray, valueOfElement));

$.getJSON("info.json",function(data){
   $("#info").html("");
   $.each(data.comments, function(iIndex,item){
       $("#info").append("<div>"+item.id+"</div>"+
          "<div>"+item.nickname+"</div>"+
          "<div>"+item.content+"</div>"
       ) ;
      
    });
   });
placeholder 属性提供可描述输入字段预期值的提示信息(hint)。
该提示会在输入字段为空时显示,并会在字段获得焦点时消失。

源文档 <http://www.w3school.com.cn/html5/att_input_placeholder.asp>
源文档 <http://www.cnblogs.com/codeplus/archive/2011/07/18/2109544.html>
源文档 <http://javascript.ruanyifeng.com/oop/inheritance.html>

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值