this的应用
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title> <script> /*
alert(this); window fn1(this);
function fn1(obj){
obj => window
} oDiv.onclick = function (){
this
fn1(this);
};
function fn1(obj){ obj => oDiv }
*/ window.onload = function (){
var aBtn = document.getElementsByTagName('input');
var that = null; // 空 for(var i=; i<aBtn.length; i++){
/*
aBtn[i].onclick = function (){
// this.style.background = 'yellow'; that = this; fn1();
};
*/
aBtn[i].onclick = fn1;
} function fn1(){
// this => window
// that.style.background = 'yellow'; // this.style.background = 'red';
}
};
</script> </head> <body> <input type="button" value="按钮1" />
<input type="button" value="按钮2" />
<input type="button" value="按钮3" /> </body>
</html>
随机推荐
- Linux添加软件连接方法
这是linux中一个非常重要命令,请大家一定要熟悉.它的功能是为某一个文件或目录在另外一个位置建立一个同步的链接,类似Windows下的超级链接. 这个命令最常用的参数是-s,具体用法是:sudo l ...
- webapi中的扩展点
Extension Points Web API provides extension points for some parts of the routing process. Interface ...
- 【笔记】Loadrunner添加OS类型为Linux的服务器
参考文章:http://www.51testing.com/?uid-145985-action-spacelist-type-blog-itemtypeid-11954 在给Loadrunner添加 ...
- k个区间相交的段落数 Educational Codeforces Round 4 D
http://codeforces.com/contest/612/problem/D 题目大意:给你n个区间,这n个区间会有相交的部分,如果一个区间相交的部分>=k,那么就把这个区间记录下来. ...
- Hibernate框架--关联映射,一对多,多对多 inverse cascade
回顾Hibernate: 1. hibernate开发环境搭建 ----> 引入jar: hibernate.jar + required + jpa + 驱动包 ---> hiberna ...
- CSS3--阴影,渐变,背景图片
文字阴影.element{ text-shadow:1px 1px 1px #cccccc;}先右再下第一个值:右侧阴影的大小第二个值:下方阴影的大小第三个值:模糊距离(阴影从开始变淡到完全消失的距离 ...
- sql语句-排序后加入序号再运算判断取想要的项
select a.id as aid,b.id as bid,a.city,a.cang,a.sid,a.time as atime,b.time as btime,a.price as aprice ...
- VMware 8安装苹果操作系统Mac OS X 10.7 Lion正式版
今天介绍下VM8下安装Mac OS X 10.7 1.工具篇 下载Vmware Workstation 8.0正式版http://115.com/file/bhyk1l2u# ...
- jquery操作HTML5 的data-*的用法实例分享
.mm{width:256px; height:200px;} .mm[data-name='张含韵']{background:url(http://image.zhangxinxu.com/imag ...
- hdu_5802_Windows 10(贪心)
题目链接:hdu_5802_Windows 10 题意: 给你两个音量a,b,要让你将音量a变到音量b,up:每秒只能一次加1的音量,down:如果连续按x秒,那么就会减2x-1的音量 题解: 对于a ...