jQuery返回值:jQuery对象

$(function(){
    //返回值
    alert($); //jQuery
    //以下返回的全是jQuery对象
    alert($());
    alert($('#box'));
    alert($('#box').css('color','red'));
    //因为返回的是jQuery对象,所以可以连缀调用
    $('#box').css('color','red').css('font-size','100px');
});

 对象互换:返回原生对象

$(function(){
    //如果使用jQuery里面没有的东西,需要返回原生的DOM对象,不能老是返回的jQuery对象,这就是对象互换
    alert(document.getElementById('box'));
    alert($('#box').get(0));//上边写法太烦,使用jQuery提供的方法
});

 另:$('#box').get(0); = $('#box').[0];

posted @ 2017-02-11 10:17  党兴明  阅读(4987)  评论(0编辑  收藏  举报