<body> | |
<button type="button">按钮1</button> | |
<button type="button">按钮2</button> | |
<button type="button">按钮3</button> | |
<script> | |
var aBtn = document.getElementsByTagName("button"); | |
var that = null; | |
function changeBg(){ | |
that.style.backgroundColor = "yellow"; | |
} | |
for(var i=0;i<aBtn.length;i++){ | |
aBtn[i].onclick = function (){ | |
that = this; | |
changeBg(); | |
}; | |
} | |
</script> |
that与this的应用实例
猜你喜欢
转载自blog.csdn.net/cosmos033/article/details/80397681
今日推荐
周排行