我是对JavaScript不太了解,触发事件必须要用id命名的对象才能触发事件吗?
<!doctype html>
<html lang="utf-8">
<head>
<title></title>
</head>
<style>
ul{
list-style-type: none;
}
li.width{
margin: 30px auto;
padding: 30px;
}
li.width{
width: 50px;
height: 50px;
color: #000000;
font-size: 20px;
line-height: 50px;
background: #f5f5f5;
}
</style>
<body>
<ul>
<li class="width">1111111</li>
</ul>
</body>
<script>
var Lis = document.getElementsByClassName("width")
Lis.onmouseout = function(){
this.style.backgroundColor = "#f5f5f5";
this.style.borderBottom = "1px solid #f5f5f5";
}
Lis.onmouseover = function(){
this.style.backgroundColor = "#FFF";
}
</script>
</html>