您的位置:首页 > Web前端 > CSS

Ferris教程学习笔记:js示例2.4 鼠标移入改变样式,鼠标移出恢复

2013-12-11 16:26 567 查看
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>鼠标移入/移出改变样式</title>
<style type="text/css">
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>
</head>
<body>
<div class="" id="div1">鼠标移入改变样式,鼠标移出恢复</div>
<script type="text/javascript">
window.onload = function(){
var div1 = document.getElementById("div1");

//绑定鼠标移入事件
div1.onmouseover = function(){
this.className = "hover";
}

//绑定鼠标移出事件
div1.onmouseout = function(){
this.className = "";
}
};
</script>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: