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>
随机推荐
- hdu 5874 Friends and Enemies icpc大连站网络赛 1007 数学
#include<stdio.h> #include<iostream> #include<algorithm> #include<math.h> #i ...
- mac 隐藏 显示 文件
显示:defaults write com.apple.finder AppleShowAllFiles -bool true隐藏:defaults write com.apple.finder Ap ...
- 第三次冲刺spring会议(第五次会议)
[例会时间]2014/5/24 21:15 [例会地点]9#446 [例会形式]轮流发言 [例会主持]马翔 [例会记录]兰梦 小组成员:兰梦 ,马翔,李金吉,赵天,胡佳奇
- iOS自定义转场动画的实现
iOS中熟悉的是导航栏中的push和pop这两种动画效果,在这里我们可以自己实现自己想要的一些转场动画 下面是我自己创建转场动画的过程 1.新建一个文件继承自NSObject ,遵循协议UIViewC ...
- 2015 Multi-University Training Contest 10
1001 CRB and Apple 1002 CRB and Candies 1003 CRB and Farm 1004 CRB and Graph 1005 CRB and His Birthd ...
- 3.1 Data Member的绑定
文章开始提出了一段示例代码,并讨论了返回哪个x的问题.然后 a) 给出了我们普遍认为正确的回答,并肯定了这个想法: b) 提醒大家,这在以前的编译器实现中,并非正确. 在早期的实现中,首 ...
- iOS学习笔记(01) - 泛型
决定新开一坑,在不断学习的同时分享自己的学习历程给大家,既是对自己学习的记录,又希望能对大家提供些微的帮助. 这一篇文章主要来介绍泛型的意义.使用与声明方法等. 1.泛型:限制类型 1.1.泛型使用场 ...
- navicat查询sqlserver数据库编码
首先:查看SQLserver编码格式的SQL语句为: go SELECT COLLATIONPROPERTY('Chinese_PRC_Stroke_CI_AI_KS_WS', 'CodePage' ...
- hibernate在配置文件中配置对象关系映射文件即hbm文件路径的写法
hbm文件如果在src下,则<mapping resource="*.hbm.xml"/> 如果在实体类包中,则<mapping resource="c ...
- 项目管理实践【三】每日构建【Daily Build Using CruiseControl.NET and MSBuild】
在上一篇项目管理实践教程二.源代码控制[Source Control Using VisualSVN Server and TortoiseSVN]中我们已经讲解了如何使用TortoiseSVN和Vi ...