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;
}
});