<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
list-style-type: none;
}
ul{
display: flex;
}
li{
width: 200px;
height: 40px;
text-align: center;
line-height: 40px;
border: 1px solid gray;
}
div{
width: 606px;
height: 606px;
display: none;
}
</style>
</head>
<body>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
<div style="background-color: red;display: block;"></div>
<div style="background-color: green;"></div>
<div style="background-color: pink;"></div>
<script>
var li =document.getElementsByTagName("li");
var div =document.getElementsByTagName("div")
for(var i=0;i<=li.length;i++){
li[i].aaa=i;
li[i].οnclick=function(){
//alert("66")
console.log(this.aaa)
}
}
</script>
</body>
</html>