js实现添加删除类名active
程序员文章站
2022-05-06 11:38:06
...
<!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>
上一篇: js改变样式效果
下一篇: js实现模仿面板效果