标签:
1. 防止this重名,可以通过设置值,然后通过参数传递过去
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<input type="button" value="按钮1"/>
<input type="button" value="按钮2"/>
<input type="button" value="按钮3"/>
<script>
window.onload = function(){
var aBtn = document.getElementsByTagName(‘input‘);
for (var i = 0; i < aBtn.length; i++) {
aBtn[i].onclick = function(){
var _this = this;
changeBackground(_this);//前面不带东西 就是 : window.changeBackground(_this)
}
}
}
function changeBackground(_this){
_this.style.background = ‘red‘;
}
</script>
</body>
</html>
标签:
原文地址:http://www.cnblogs.com/bravolove/p/5979144.html