您的位置:首页 > Web前端 > JQuery

jQuery里面用this和用$(this)有什么区别?

2016-09-09 14:39 489 查看
转自:http://zhidao.baidu.com/question/258783817.html

this表示的是javascript提供的当前对象
$(this)表示的是用jquery封装候的当前对象
this对象可以直接用this.style修改样式
$(this)可以使用jquery提供的方法访问样式
比如this.style.display="none"在jquery中可以用$(this).css("display","none")实现


this 当前对象。
$(this) jquery对象
前则不能直接访问jquery方法。

$(function(){
$('button').click(function(){
//$(this)表示当前对象,在这里指的是button按钮
$(this).closest('tr').remove();
//或者:
$(this).parent().parent().remove();
//或者:
$(this).parents('tr').remove();
})
})
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: