js实现添加删除类名active
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.active{
width: 100px;
height: 100px;
background-color: #0000FF;
}
</style>
</head>
<body>
<div class="dd" id="box">dd</div>
<script type="text/javascript">
var box = document.getElementById('box')
var cl = box.className;
// console.log(cl);
// console.log(box);
box.onmouseover = function(){
box.className += ' active';
}
box.onmouseout = function(){
box.className = cl;
}
</script>
</body>
</html>
本文来自博客园,作者:JackieDYH,转载请注明原文链接:https://www.cnblogs.com/JackieDYH/p/17634860.html