以下是html页面的代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>中国的流浪猫
</title>
<link rel="stylesheet" type="text/css" href="regality.css">
</head>
<body>
<div class="wrapper" style="width: 400px;height: 400px;background-color: red">
<div class="box" style="width: 100px;height: 100px;background-color: yellow"></div>
</div>
<script type="text/javascript" src="lesson.js">
</script>
</body>
</html>
以下是JavaScript页面的代码:
var wrapper
= document
.getElementsByClassName('wrapper')[0];
var box
= document
.getElementsByClassName('box')[0];
wrapper
.onclick = function(e
) {
var event
= e
|| window
.event
;
var target
= event
.target
|| event
.srcElement
;
console
.log(target
);
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-1873.html