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

作品第一课----鼠标移入/移除改变样式

2015-12-23 21:55 579 查看
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
div { width: 200px; height: 200px; background-color: #000; color: #FFF; margin: 0 auto; }
.style { border: 10px solid #000; background-color: red; color: yellow; }

</style>
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
<div>
<p>鼠标移入改变样式,鼠标移除恢复。</p>
</div>
<script type="text/javascript">
$(document).ready(function(){
$("div").hover(
function(){
$(this).addClass("style");
},
function(){
$(this).removeClass("style");
}
);
});

// var handlerInOut = function(){
//     alert(1)
// };
// $('div').bind("mouseenter mouseleave", handlerInOut);
//$("div").hover(handlerInOut);

</script>

</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: