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>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章