首页 > 其他 > 详细

$(this) 和 this

时间:2016-01-30 13:55:24      阅读:187      评论:0      收藏:0      [点我收藏+]

在使用 jQuery 时,$(this) 和 this 具体指:

    this :是当前 DOM 对象;

    $(this) 是jQuery对象;

例子:

<input type="text">
$(function(){
    $("#search_id").focus(function(){
        alert(this);   //弹出值为: object HTMLInputElement
        alert($(this)); //弹出值为:object object
        })
       })

jQuery 对象和 DOM 对象 是可以相互转化的 : jQuery  ($varJD) 转DOM  (JD) :JD=$varJD[0] ; JD=$varJD.get(0) 。DOM  (JD)转 jQuery  ($varJD):$varJD=$(JD);

可以带入上边验证:$(this)[0],将会弹出 object HTMLInputElement。

$(this) 和 this

原文:http://www.cnblogs.com/CHWYH/p/5170878.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!