jQuery中this与$(this)的区别

来源:互联网 发布:手机淘宝怎么改评价啊 编辑:程序博客网 时间:2024/04/28 04:55

this是一个Html 元素

$(this)是一个JQuery对象

两者拥有的属性是不同的。

下面举例说明:

两段程序的效果是相同的,但分别使用了$(this)和this

$("input[name='out[]']").each(function() {
                if($(this).attr("checked")==true)
                {
                    
                    $(this).attr("checked",false);
                }
                else
                {
                    $(this).attr("checked",true);
                }

});
 $("input[name='out[]']").each(function() {
                    if(this.checked)
                    {
                        this.checked = false;
                    }
                    else
                    {
                        this.checked = true;
                    }
                  });

0 0
原创粉丝点击