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>
posted @ 2020-02-14 14:33  Stary_tx  阅读(133)  评论(0编辑  收藏  举报