<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> #
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#box{
width: 500px;
height: 500px;
background-color: pink;
}
#one{
width: 50px;
height: 100px;
background-color: red;
margin:20px;
}
#two{
width: 50px;
height: 100px;
background-color: red;
margin:20px;
}
#three{
width: 50px;
height: 100px;
background-color: red;
margin:20px;
}
</style>
</head>
<body>
<div id='box'>
<div id='one'></div>
<div id='two'></div>
<div id='three'></div>
</div>
<script>
var box=document.getElementById('box');
box.onclick=function(e){
console.log(e.target.id)
switch(e.target.id){
case 'one':
alert("one");
break;
case 'two':
alert("two");
break;
case 'three':
alert('three');
break;
}
}
</script>
</body>
</html>