<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<style>
body{color:#fff;font:12px/1.5 Tahoma;}
#div1{width:150px;height:150px;margin:0 auto;padding:10px;background:black;border:10px solid #000;cursor:crosshair;}
#div1.hover{color:red;background:#f0f0f0;border:10px solid red;}
</style>
<script>
window.onload = function ()
{
var oDiv = document.getElementById("div1");
oDiv.onmouseover = function ()
{
oDiv.className = "hover"
};
oDiv.onmouseout = function ()
{
oDiv.className = ""
}
};
</script>
</head>
<body>
<div id="div1">鼠标移入改变样式,鼠标移出恢复。</div>
</body>
</html>
如上述代码,为什么是oDiv.className = "hover" 可以控制的div的样式,在div中并没有定义过class,还是说hover本身就是个class类?
还请前辈解惑
qq_玩二小_0
慕莱坞8333017
icecap
qq_杀意隆_0
CodeManDSH
相关分类