如果你要使用html元素本身的屬性或方法就需要使用this,如果你要使用jQuery包裝后的方法或屬性就要$(this),一般則有如下的關系.
復制代碼 代碼如下:
$(this)[0] == this;
復制代碼 代碼如下:
<a target="_blank" data-id="1010000000125418">jQuery</a>
復制代碼 代碼如下:
$('a').click(function(){
this.innerHTM==$(this).html()=='jQuery';//三者是一樣的.
this.getAttribute('href')==this.href==$(this).attr('href')//三者是一樣的;
this.getAttribute('target')==this.target==$(this).attr('target')//三者是一樣的;
this.getAttribute('data-id')==$(this).attr('data-id')//二者是一樣的;
});
新聞熱點
疑難解答
圖片精選