<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
*{padding: 0px;margin: 0px;}
ul{list-style: none;}
.wrap{width: 500px;height: 500px;border: 1px solid red;margin: 60px 0px 0px 60px;}
ul{margin-left: 20px;margin-top: 30px; border: 1px dashed brown;
position: relative;
}
li{width:50px;height: 50px;background: #e6e9ea;margin-top: 20px;}
li>div{background: #8ce3fc;width: 150px;height: 190px;
position: absolute;
top: 20px;
left: 50px;
}
/*#b>div{background: #8ce3fc;width: 150px;height: 190px;
position: absolute;
top: 30px;
left: 50px;
}*/
li:hover{background: #8ce3fc;}
.hid{display: none;}
.show{display: block;}
</style>
</head>
<body>
<div class="wrap">
<ul>
<li id="a" onmouseover="over('a')" onmouseout="out('a')"> <!--对于over(ID) 函数,在调用时传入id的时候,只能用 ''单引号,""双引号不行-->
<span>1</span>
<div id="ad" class="hid">
hello_1
</div>
</li>
<li id="b" onmouseover="over('b')" onmouseout="out('b')">
<span>2</span>
<div id="bd" class="hid">
hello_2
</div>
</li>
<li id="c" onmouseover="over('c')" onmouseout="out('c')">
<span>3</span>
<div id="cd" class="hid">
hello_3
</div>
</li>
</ul>
</div>
<script type="text/javascript">
function over(ID){
var o = document.getElementById(ID).getElementsByTagName("div")[0].className="show";
}
function out(ID){
var o = document.getElementById(ID).getElementsByTagName("div")[0].className="hid";
}
</script>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
*{padding: 0px;margin: 0px;}
ul{list-style: none;}
.wrap{width: 500px;height: 500px;border: 1px solid red;margin: 60px 0px 0px 60px;}
ul{margin-left: 20px;margin-top: 30px; border: 1px dashed brown;
position: relative;
}
li{width:50px;height: 50px;background: #e6e9ea;margin-top: 20px;}
li>div{background: #8ce3fc;width: 150px;height: 190px;
position: absolute;
top: 20px;
left: 50px;
}
/*#b>div{background: #8ce3fc;width: 150px;height: 190px;
position: absolute;
top: 30px;
left: 50px;
}*/
li:hover{background: #8ce3fc;}
.hid{display: none;}
.show{display: block;}
</style>
</head>
<body>
<div class="wrap">
<ul>
<li id="a" onmouseover="over('a')" onmouseout="out('a')"> <!--对于over(ID) 函数,在调用时传入id的时候,只能用 ''单引号,""双引号不行-->
<span>1</span>
<div id="ad" class="hid">
hello_1
</div>
</li>
<li id="b" onmouseover="over('b')" onmouseout="out('b')">
<span>2</span>
<div id="bd" class="hid">
hello_2
</div>
</li>
<li id="c" onmouseover="over('c')" onmouseout="out('c')">
<span>3</span>
<div id="cd" class="hid">
hello_3
</div>
</li>
</ul>
</div>
<script type="text/javascript">
function over(ID){
var o = document.getElementById(ID).getElementsByTagName("div")[0].className="show";
}
function out(ID){
var o = document.getElementById(ID).getElementsByTagName("div")[0].className="hid";
}
</script>
</body>
</html>
本文介绍了一种使用CSS样式和JavaScript代码来实现列表项在鼠标悬停时显示隐藏内容的方法。通过设置特定的样式和事件监听函数,可以为网页中的列表项增加动态交互效果。
1398

被折叠的 条评论
为什么被折叠?



