发布网友
共2个回答
热心网友
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>menu</title>
<style type="text/css">
div.box {
width: 100px;
height: 25px;
text-align: center;
cursor: pointer;
border: 1px solid black;
float: left;
background-color: yellow;
}
span.ad {
display: none;
width: 406px;
height: 500px;
border: 1px solid black;
position: absolute;
left: 8px;
top: 34px;
background-color: orange;
}
</style>
<script type="text/javascript" src="jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$ (function ()
{
var box = $ ("div.box");
var span = box.children ("span.ad");
box.click (function (e)
{
var me = $ (this);
if (e.target !== me[0])
{
return false;
}
var mc = me.children ("span.ad");
mc.is (":hidden") ? me.css ("backgroundColor", "orange").siblings ("div.box").css ("backgroundColor",
"yellow") : box.css ("backgroundColor", "yellow");
var temp = box.has ("span.ad:visible");
if (temp[0] !== me[0])
{
temp.children ("span.ad").hide ();
}
mc.stop ().slideToggle ("slow");
});
})
</script>
</head>
<body>
<div class="box">
hello <span class="ad">Joey Wheel</span>
</div>
<div class="box">
kitty <span class="ad">Kaiba</span>
</div>
<div class="box">
flash <span class="ad">Yugi</span>
</div>
<div class="box">
world <span class="ad">Kyo Kusanagi</span>
</div>
</body>
</html>
热心网友
教你一个方法 使用标识 比如在给ad添加一个 ad1的属性 直接定义click事件 判断样式是否存在 存在执行 true 不存在再执行 false