欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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实现添加删除类名active

 

相关标签: JavaScript学习