怎么点击按钮 只显示当前的要显示的div $(".total-scope-tan").toggle();=》$(this).find(".total-scope-tan").toggle(); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $(".total-scope-tan").toggle();toggle $(document).ready(function() { $(".total-scope").each(function(){ $(this).click(function(){ console.log($(this)) $(".total-scope-tan").hide(); $(this).find('.total-scope-tan').show(); }) }) }); <!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" xml:lang="en"><head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>Document</title> <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script> <script type="text/javascript"> $(function () { $(".total-scope").each(function(){ $(this).click(function(){ $(".total-scope-tan").hide(); $(this).children('.total-scope-tan').show(); }) }) }); </script> <style type="text/css"> *{margin: 0; padding: 0; } .total-scope { width: 118px; height: 20px; border: 1px solid #DCDCDC; background: #F6F6F6; float: left; line-height: 20px; margin: 7px 0 0 10px; display: inline; cursor: pointer; position: relative;}.total-scope .total-scope-tan{ width: 118px; border: 1px solid #DCDCDC; border-top: 0; border-bottom: 0; background: #FFF; position: absolute; top:21px; left: -1px; z-index: 99; display: none;}.total-scope-tan a{ width: 118px; height: 20px; display: inline-block; border-bottom: 1px solid #DCDCDC; color: #7D7D7D; line-height: 20px; text-align: center;}.total-scope-tan a:hover{ background: #F6F6F6; color: #E64545;} </style></head><body> <div class="total-scope"> <span>最近7天</span> <div class="total-scope-tan"> <a href="#">最近6天</a> <a href="#">最近5天</a> <a href="#">最近4天</a> </div> </div> <div class="total-scope"> <span>最近7天</span> <div class="total-scope-tan"> <a href="#">最近6天</a> <a href="#">最近5天</a> <a href="#">最近4天</a> </div> </div> <div class="total-scope"> <span>最近7天</span> <div class="total-scope-tan"> <a href="#">最近6天</a> <a href="#">最近5天</a> <a href="#">最近4天</a> </div> </div></body></html> $(".total-scope").each(function(){ $(this).click(function(){ console.log($(this)) $(".total-scope-tan").hide(); $(this).find('.total-scope-tan').toggle(); $(document).one("click", function () {//对document绑定一个隐藏Div方法 $(".total-scope-tan").hide(); }); event.stopPropagation();//阻止事件向上冒泡 }); $(".total-scope-tan").click(function (event) { event.stopPropagation();//阻止事件向上冒泡 }); })请问下 toggle()不起作用是怎么回事 把$(".total-scope-tan").hide();改成$(this).siblings('.total-scope').find('.total-scope-tan').hide(); $(".total-scope-tan").hide();//该句删掉,没必要,直接利用下面的toggle即可 $(this).find('.total-scope-tan').toggle(); $(function () { $(".total-scope").find("span").click(function () { $(this).next().toggle(); }); }) 请问下 你这样toggle有效果 可是当我点击第二个total-scope 第一个显示的total-scope-tan没有隐藏 请问下应该这么做啊 $(document).ready(function() { $(".total-scope").each(function(){ $(this).click(function(event){ console.log($(this)) $(this).siblings('.total-scope').find('.total-scope-tan').hide(); $(this).find(".total-scope-tan").show(); $(document).one("click", function () {//对document绑定一个隐藏Div方法 $(".total-scope-tan").hide(); }); event.stopPropagation();//阻止事件向上冒泡 }); $(".total-scope-tan").click(function (event) { event.stopPropagation();//阻止事件向上冒泡 }); }) });请问下 改成这样还是没有toggle效果 <!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" xml:lang="en"><head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>Document</title> <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $(".total-scope").each(function(){ $(this).click(function(){ $(this).siblings('.total-scope').find('.total-scope-tan').hide(); $(this).find('.total-scope-tan').toggle(); }) }) }); </script> <style type="text/css"> *{margin: 0; padding: 0; } .total-scope { width: 118px; height: 20px; border: 1px solid #DCDCDC; background: #F6F6F6; float: left; line-height: 20px; margin: 7px 0 0 10px; display: inline; cursor: pointer; position: relative;}.total-scope .total-scope-tan{ width: 118px; border: 1px solid #DCDCDC; border-top: 0; border-bottom: 0; background: #FFF; position: absolute; top:21px; left: -1px; z-index: 99; display: none;}.total-scope-tan a{ width: 118px; height: 20px; display: inline-block; border-bottom: 1px solid #DCDCDC; color: #7D7D7D; line-height: 20px; text-align: center;}.total-scope-tan a:hover{ background: #F6F6F6; color: #E64545;} </style></head><body> <div class="total-scope"> <span>最近7天</span> <div class="total-scope-tan"> <a href="#">最近6天</a> <a href="#">最近5天</a> <a href="#">最近4天</a> </div> </div> <div class="total-scope"> <span>最近7天</span> <div class="total-scope-tan"> <a href="#">最近6天</a> <a href="#">最近5天</a> <a href="#">最近4天</a> </div> </div> <div class="total-scope"> <span>最近7天</span> <div class="total-scope-tan"> <a href="#">最近6天</a> <a href="#">最近5天</a> <a href="#">最近4天</a> </div> </div></body></html>你用这个测试 我这是没问题的啊 是的 没有问题<!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" xml:lang="en"><head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>Document</title> <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $(".total-scope").each(function(){ $(this).click(function(event){ $(this).siblings('.total-scope').find('.total-scope-tan').hide(); $(this).find('.total-scope-tan').toggle(); $(document).one("click", function () {//对document绑定一个影藏Div方法 $('.total-scope-tan').hide(); }); event.stopPropagation();//阻止事件向上冒泡 }) $('.total-scope-tan').click(function (event) { event.stopPropagation();//阻止事件向上冒泡 }); }) }); </script> <style type="text/css"> *{margin: 0; padding: 0; } .total-scope { width: 118px; height: 20px; border: 1px solid #DCDCDC; background: #F6F6F6; float: left; line-height: 20px; margin: 7px 0 0 10px; display: inline; cursor: pointer; position: relative;}.total-scope .total-scope-tan{ width: 118px; border: 1px solid #DCDCDC; border-top: 0; border-bottom: 0; background: #FFF; position: absolute; top:21px; left: -1px; z-index: 99; display: none;}.total-scope-tan a{ width: 118px; height: 20px; display: inline-block; border-bottom: 1px solid #DCDCDC; color: #7D7D7D; line-height: 20px; text-align: center;}.total-scope-tan a:hover{ background: #F6F6F6; color: #E64545;} </style></head><body><div style="float:left;"> <div class="total-scope"> <span>最近7天</span> <div class="total-scope-tan"> <a href="#">最近6天</a> <a href="#">最近5天</a> <a href="#">最近4天</a> </div> </div></div><div style="float:left;"> <div class="total-scope"> <span>最近7天</span> <div class="total-scope-tan"> <a href="#">最近6天</a> <a href="#">最近5天</a> <a href="#">最近4天</a> </div> </div></div><div style="float:left;"> <div class="total-scope"> <span>最近7天</span> <div class="total-scope-tan"> <a href="#">最近6天</a> <a href="#">最近5天</a> <a href="#">最近4天</a> </div> </div></div></body></html>麻烦帮我看看这个 这个外面又包了div 就不起作用了 请问是怎么回事 是因为你的结构改了 对应的语句也要跟着改$(this).parent().siblings('div').find('.total-scope-tan').hide(); 你可以考虑如下实现,而不用去管外层的嵌套结构<!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" xml:lang="en"><head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>Document</title> <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $(".total-scope").each(function(index, element){ $(this).click(function(event){ $('.total-scope-tan:not(:eq('+index+'))').hide(); $(this).find('.total-scope-tan').toggle(); $(document).one("click", function () {//对document绑定一个影藏Div方法 $('.total-scope-tan').hide(); }); event.stopPropagation();//阻止事件向上冒泡 }) $('.total-scope-tan').click(function (event) { event.stopPropagation();//阻止事件向上冒泡 }); }) }); </script> <style type="text/css"> *{margin: 0; padding: 0; } .total-scope { width: 118px; height: 20px; border: 1px solid #DCDCDC; background: #F6F6F6; float: left; line-height: 20px; margin: 7px 0 0 10px; display: inline; cursor: pointer; position: relative;}.total-scope .total-scope-tan{ width: 118px; border: 1px solid #DCDCDC; border-top: 0; border-bottom: 0; background: #FFF; position: absolute; top:21px; left: -1px; z-index: 99; display: none;}.total-scope-tan a{ width: 118px; height: 20px; display: inline-block; border-bottom: 1px solid #DCDCDC; color: #7D7D7D; line-height: 20px; text-align: center;}.total-scope-tan a:hover{ background: #F6F6F6; color: #E64545;} </style></head><body><div style="float:left;"> <div class="total-scope"> <span>最近7天</span> <div class="total-scope-tan"> <a href="#">最近6天</a> <a href="#">最近5天</a> <a href="#">最近4天</a> </div> </div></div><div style="float:left;"> <div class="total-scope"> <span>最近7天</span> <div class="total-scope-tan"> <a href="#">最近6天</a> <a href="#">最近5天</a> <a href="#">最近4天</a> </div> </div></div><div style="float:left;"> <div class="total-scope"> <span>最近7天</span> <div class="total-scope-tan"> <a href="#">最近6天</a> <a href="#">最近5天</a> <a href="#">最近4天</a> </div> </div></div></body></html> 请问下 $(this).find('.total-scope-tan').toggle(); 在ie7 8下不起作用 是怎么回事啊 JavaScript 服务器请求问题 仿qq的消息提醒问题 执行button的onclientclick 后 textbox内容被清空 两个相同名称的控件,服务器如何接收 ctrl+回车提交表单的问题 在text搜索栏里如何像baidu那样保存浏览的历史记录? 求关于验证 字符串 chrome 上奇怪的问题 xml问题 求指教,写了个连接mysql的模糊搜索的代码,tomcat运行有错、但是不知道错在哪里 关于RGraph.Line作图的问题 Jquery动态添加的li实现键盘控制li
toggle
$(this).click(function(){
console.log($(this))
$(".total-scope-tan").hide();
$(this).find('.total-scope-tan').show();
})
})
});
<!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" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript"> $(function () {
$(".total-scope").each(function(){
$(this).click(function(){
$(".total-scope-tan").hide();
$(this).children('.total-scope-tan').show();
})
})
}); </script>
<style type="text/css">
*{margin: 0;
padding: 0;
}
.total-scope {
width: 118px;
height: 20px;
border: 1px solid #DCDCDC;
background: #F6F6F6;
float: left;
line-height: 20px;
margin: 7px 0 0 10px;
display: inline;
cursor: pointer;
position: relative;
}
.total-scope .total-scope-tan{
width: 118px;
border: 1px solid #DCDCDC;
border-top: 0;
border-bottom: 0;
background: #FFF;
position: absolute;
top:21px;
left: -1px;
z-index: 99;
display: none;
}
.total-scope-tan a{
width: 118px;
height: 20px;
display: inline-block;
border-bottom: 1px solid #DCDCDC;
color: #7D7D7D;
line-height: 20px;
text-align: center;
}
.total-scope-tan a:hover{
background: #F6F6F6;
color: #E64545;
}
</style>
</head>
<body>
<div class="total-scope">
<span>最近7天</span>
<div class="total-scope-tan">
<a href="#">最近6天</a>
<a href="#">最近5天</a>
<a href="#">最近4天</a>
</div>
</div>
<div class="total-scope">
<span>最近7天</span>
<div class="total-scope-tan">
<a href="#">最近6天</a>
<a href="#">最近5天</a>
<a href="#">最近4天</a>
</div>
</div>
<div class="total-scope">
<span>最近7天</span>
<div class="total-scope-tan">
<a href="#">最近6天</a>
<a href="#">最近5天</a>
<a href="#">最近4天</a>
</div>
</div>
</body>
</html>
$(this).click(function(){
console.log($(this))
$(".total-scope-tan").hide();
$(this).find('.total-scope-tan').toggle();
$(document).one("click", function () {//对document绑定一个隐藏Div方法
$(".total-scope-tan").hide();
});
event.stopPropagation();//阻止事件向上冒泡
});
$(".total-scope-tan").click(function (event) {
event.stopPropagation();//阻止事件向上冒泡
});
})
请问下 toggle()不起作用是怎么回事
$(this).find('.total-scope-tan').toggle();
$(".total-scope").find("span").click(function () {
$(this).next().toggle();
});
})
$(document).ready(function() {
$(".total-scope").each(function(){
$(this).click(function(event){
console.log($(this))
$(this).siblings('.total-scope').find('.total-scope-tan').hide();
$(this).find(".total-scope-tan").show();
$(document).one("click", function () {//对document绑定一个隐藏Div方法
$(".total-scope-tan").hide();
});
event.stopPropagation();//阻止事件向上冒泡
});
$(".total-scope-tan").click(function (event) {
event.stopPropagation();//阻止事件向上冒泡
});
})
});请问下 改成这样还是没有toggle效果
<!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" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function() { $(".total-scope").each(function(){
$(this).click(function(){
$(this).siblings('.total-scope').find('.total-scope-tan').hide();
$(this).find('.total-scope-tan').toggle();
})
})
});
</script>
<style type="text/css">
*{margin: 0;
padding: 0;
}
.total-scope {
width: 118px;
height: 20px;
border: 1px solid #DCDCDC;
background: #F6F6F6;
float: left;
line-height: 20px;
margin: 7px 0 0 10px;
display: inline;
cursor: pointer;
position: relative;
}
.total-scope .total-scope-tan{
width: 118px;
border: 1px solid #DCDCDC;
border-top: 0;
border-bottom: 0;
background: #FFF;
position: absolute;
top:21px;
left: -1px;
z-index: 99;
display: none;
}
.total-scope-tan a{
width: 118px;
height: 20px;
display: inline-block;
border-bottom: 1px solid #DCDCDC;
color: #7D7D7D;
line-height: 20px;
text-align: center;
}
.total-scope-tan a:hover{
background: #F6F6F6;
color: #E64545;
}
</style>
</head>
<body>
<div class="total-scope">
<span>最近7天</span>
<div class="total-scope-tan">
<a href="#">最近6天</a>
<a href="#">最近5天</a>
<a href="#">最近4天</a>
</div>
</div>
<div class="total-scope">
<span>最近7天</span>
<div class="total-scope-tan">
<a href="#">最近6天</a>
<a href="#">最近5天</a>
<a href="#">最近4天</a>
</div>
</div>
<div class="total-scope">
<span>最近7天</span>
<div class="total-scope-tan">
<a href="#">最近6天</a>
<a href="#">最近5天</a>
<a href="#">最近4天</a>
</div>
</div>
</body>
</html>你用这个测试 我这是没问题的啊
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".total-scope").each(function(){
$(this).click(function(event){
$(this).siblings('.total-scope').find('.total-scope-tan').hide();
$(this).find('.total-scope-tan').toggle();
$(document).one("click", function () {//对document绑定一个影藏Div方法
$('.total-scope-tan').hide();
});
event.stopPropagation();//阻止事件向上冒泡
})
$('.total-scope-tan').click(function (event) {
event.stopPropagation();//阻止事件向上冒泡
});
})
});
</script>
<style type="text/css">
*{margin: 0;
padding: 0;
}
.total-scope {
width: 118px;
height: 20px;
border: 1px solid #DCDCDC;
background: #F6F6F6;
float: left;
line-height: 20px;
margin: 7px 0 0 10px;
display: inline;
cursor: pointer;
position: relative;
}
.total-scope .total-scope-tan{
width: 118px;
border: 1px solid #DCDCDC;
border-top: 0;
border-bottom: 0;
background: #FFF;
position: absolute;
top:21px;
left: -1px;
z-index: 99;
display: none;
}
.total-scope-tan a{
width: 118px;
height: 20px;
display: inline-block;
border-bottom: 1px solid #DCDCDC;
color: #7D7D7D;
line-height: 20px;
text-align: center;
}
.total-scope-tan a:hover{
background: #F6F6F6;
color: #E64545;
}
</style>
</head>
<body>
<div style="float:left;">
<div class="total-scope">
<span>最近7天</span>
<div class="total-scope-tan">
<a href="#">最近6天</a>
<a href="#">最近5天</a>
<a href="#">最近4天</a>
</div>
</div>
</div>
<div style="float:left;">
<div class="total-scope">
<span>最近7天</span>
<div class="total-scope-tan">
<a href="#">最近6天</a>
<a href="#">最近5天</a>
<a href="#">最近4天</a>
</div>
</div>
</div>
<div style="float:left;">
<div class="total-scope">
<span>最近7天</span>
<div class="total-scope-tan">
<a href="#">最近6天</a>
<a href="#">最近5天</a>
<a href="#">最近4天</a>
</div>
</div>
</div>
</body>
</html>麻烦帮我看看这个 这个外面又包了div 就不起作用了 请问是怎么回事
$(this).parent().siblings('div').find('.total-scope-tan').hide();
<!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" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".total-scope").each(function(index, element){
$(this).click(function(event){
$('.total-scope-tan:not(:eq('+index+'))').hide();
$(this).find('.total-scope-tan').toggle();
$(document).one("click", function () {//对document绑定一个影藏Div方法
$('.total-scope-tan').hide();
});
event.stopPropagation();//阻止事件向上冒泡
})
$('.total-scope-tan').click(function (event) {
event.stopPropagation();//阻止事件向上冒泡
});
})
});
</script>
<style type="text/css">
*{margin: 0;
padding: 0;
}
.total-scope {
width: 118px;
height: 20px;
border: 1px solid #DCDCDC;
background: #F6F6F6;
float: left;
line-height: 20px;
margin: 7px 0 0 10px;
display: inline;
cursor: pointer;
position: relative;
}
.total-scope .total-scope-tan{
width: 118px;
border: 1px solid #DCDCDC;
border-top: 0;
border-bottom: 0;
background: #FFF;
position: absolute;
top:21px;
left: -1px;
z-index: 99;
display: none;
}
.total-scope-tan a{
width: 118px;
height: 20px;
display: inline-block;
border-bottom: 1px solid #DCDCDC;
color: #7D7D7D;
line-height: 20px;
text-align: center;
}
.total-scope-tan a:hover{
background: #F6F6F6;
color: #E64545;
}
</style>
</head>
<body>
<div style="float:left;">
<div class="total-scope">
<span>最近7天</span>
<div class="total-scope-tan">
<a href="#">最近6天</a>
<a href="#">最近5天</a>
<a href="#">最近4天</a>
</div>
</div>
</div>
<div style="float:left;">
<div class="total-scope">
<span>最近7天</span>
<div class="total-scope-tan">
<a href="#">最近6天</a>
<a href="#">最近5天</a>
<a href="#">最近4天</a>
</div>
</div>
</div>
<div style="float:left;">
<div class="total-scope">
<span>最近7天</span>
<div class="total-scope-tan">
<a href="#">最近6天</a>
<a href="#">最近5天</a>
<a href="#">最近4天</a>
</div>
</div>
</div>
</body>
</html>