僅代表個人看法
看了一些關于jQuery中this和javaScirpt的this的區(qū)別,描述都不甚明了,很虐新。
個人感覺是兩種對象分別調(diào)取jQuery和javaScript的函數(shù)。
$this能調(diào)取jQuery類庫的函數(shù),jQuery函數(shù)更加的簡潔,兼容性更好。
當然,this對象可以通過$(this)轉(zhuǎn)換成jQuery對象。
<script type="text/javascript">
var p1 = document.getElementById('test1')
p1.addEventListener('click',function(){
//直接通過dom的方法改變顏色
this.style.color = "red";
},false);
</script>
<script type="text/javascript">
$('#test2').click(function(){
//通過包裝成jQuery對象改變顏色
$(this).css('color','blue');
})
</script>
jQuery的方法更加簡潔,好用。兼容性也會相對更好一些。