
javascript,我写了hover,但我想让鼠标移走继续保持红色,但当我移到旁边那个,第一个变回来,怎么写?
展开全部
您好:写了一个这样的效果。可以直接给你的标签上加上这个事件即可。代码如下:
<!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>
<title></title>
<script src="jquery-1.8.0/jquery-1.8.0.js" type="text/javascript"></script>
<style type="text/css">
ul{list-style:none; width:200px;}
ul li {text-align:center; float:left; margin-left:20px; border:1px solid red;}
</style>
<script type="text/javascript">
$(function () {
$("li").mouseover(function () {
$(this).css("background-color", "red").siblings().css("background-color","");
});
});
</script>
</head>
<body>
<div>
<ul>
<li>中国</li>
<li>山东</li>
</ul>
</div>
</body>
</html>
可以直接复制到网页中看效果。但是要引入jquery库哦。
<!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>
<title></title>
<script src="jquery-1.8.0/jquery-1.8.0.js" type="text/javascript"></script>
<style type="text/css">
ul{list-style:none; width:200px;}
ul li {text-align:center; float:left; margin-left:20px; border:1px solid red;}
</style>
<script type="text/javascript">
$(function () {
$("li").mouseover(function () {
$(this).css("background-color", "red").siblings().css("background-color","");
});
});
</script>
</head>
<body>
<div>
<ul>
<li>中国</li>
<li>山东</li>
</ul>
</div>
</body>
</html>
可以直接复制到网页中看效果。但是要引入jquery库哦。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |