var that=that
来源:互联网 发布:iphone长截图软件 编辑:程序博客网 时间:2024/05/17 01:56
javascript中var that=this;是什么意思
你可能会发现别人写的代码中有这么一句:var that = this;,这代表什么意思呢?
在javascript中,this代表的是当前对象。
var that=this就是将当前的this对象复制一份到that变量中。这样做有什么意义呢?
$('#zhetenga').click(function(){
//this是被点击的#zhetenga
var that = this;
$('.zhetenga').each(function(){
//this是.zhetenga循环中当前的对象
//that仍然是刚才被点击的#zhetenga
});
});
可以看到,this对象在程序中随时会改变,而var that=this之后,that没改变之前仍然是指向当时的this,这样就不会出现找不到原来的对象。
- var that=that
- var that = this
- 【JavaScript】var that = this
- javascript中var that=this
- javascript中var that=this
- javascript中var that=this
- javascript中var that=this
- JavaScript 中的 var that = this
- 为什么要写var that = this;
- that
- that
- 为什么在js中要写var this =that?
- js常见的var that = this的用法
- pushing a var of numbers that are strings into an array
- so…that,such…that ,such that
- That Troublesome "Father of"
- GROW THAT DBA CAREER
- History that still hurts
- 工作笔记(一)
- 线程间操作无效: 从不是创建控件“label1”的线程访问它。
- C++语言复习二
- 文档BMC ARS7604 DatebaseReference
- 项目概要设计书要点
- var that=that
- Android类参考---Fragment(三)
- SearchView
- linux unzip 命令详解
- XML报表
- 加锁 synchronize
- 如何用SQL语句查询一个数据表所有字段的类型
- ArcGIS点击地图查询
- 解决RTX开发问题:检索 COM 类工厂中 CLSID 为 {79210E58-99EB-45D0-8890-763EFEAA143F} 的组件时失败,原因是出现以下错误: 80040154。