javascript中this的用法

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>this</title>
</head>
<body>
<div id="div1" onclick="func(this)">hello div</div>
<script>
// document.getElementById('div1').onclick=function () {
// console.log(this.getAttribute('id'));// div1
// }
function func(self) {
console.log(self.getAttribute('id'));// div1


}
</script>

</body>
</html>
原文地址:https://www.cnblogs.com/startl/p/12307332.html