Posted on
2021-03-17 13:20晚风914
阅读(1523)
评论(0)
收藏举报
this 会随着上下文环境而变换它的指向,在当前作用域中设置一个变量用来存储 this 可以防止在其他地方找不到 this 的错误。
$("#btn").click(function(){
var that = this;//这里this和that都代表了"#btn"这个对象
$(".tr").each(function(){
this;//在这里this代表的是每个遍历到的".tr"对象
that;//仍代表"#btn"对象 })
})