新手问题:怎么实现“我开你关效果” 怎么实现点击一个“展开此价格更多航班”然后下面展开内容;然后点下面的“展开此价格更多航班”,开着的全部关掉,打开刚刚点击的这个。这个展开此价格更多航班和下面的内容是循环出来的。数目不定。怎么实现呢?展开的代码我自己写出来了,大家帮忙告诉下,怎么关联点其中一个这个开,其他就关?jquery 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $(".class").slideToggle("slow"); 滑动切换 。 贴html代码出来,别人才好根据你的代码给解决方案 没有用Jquery 说下思路每次执行函数的时候用一个变量记住当前打开的对象下次执行的时候让上一个打开的div关闭即可(思路很重要哦)写个例子<!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><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>NoName</title><style>*{padding:0;margin:0;font-size:12px;}.testDiv{width:198px;height:100px;border:1px solid #ccc;margin:0 0 5px 5px;display:none;}h5{background:#ccc;width:200px;margin:5px 0 0 5px;height:24px;line-height:24px;cursor:pointer;}</style><script>var lastObj='';function ShowMe(obj){ var ShowObj=document.getElementById(obj); ShowObj.style.display=(ShowObj.style.display=='block')?'none':'block'; if (lastObj!='') lastObj.style.display='none'; lastObj=ShowObj;}</script></head><body><h5 onclick="ShowMe('Div1')">模块1</h5><div id="Div1" class="testDiv"> 第一个栏目</div><h5 onclick="ShowMe('Div2')">模块2</h5><div id="Div2" class="testDiv"> 第二个栏目</div><h5 onclick="ShowMe('Div3')">模块3</h5><div id="Div3" class="testDiv"> 第三个栏目</div></body></html> 如果Div的ID是有序的话可以这样写function show(val){for(var i = 1 i < 4; i++){if(val == i){$("#div" + i).show();}else{$("#div" + i).hide();}}}<h5 onclick="ShowMe('2')">模块2</h5> //给所有的增加一个class,比如:class="tip",然后<script>$(function(){ $(".tip").click(function(){ $(".tip").slideUp(500); $(this).slideDown(500); })})</script> 自己手写的话,可以用display属性<div style="display:none/block"> ...... ......</div>通过改变display的属性值,none为不显示,block块状显示也可以使用插件:jQuery中有现成的,可以去找找 我支持楼上的,如果是菜鸟的话,这种方法比较简单使用table布局,然后 设置他的display属性。none为不显示,block块状显示 JS中如何生成{name1:value1}形式的数组 一道算法题,大家知无不言哈。 JSP+Tomcat 6.0的web发布时,出现错误日志,tomcat自动停止,网页白页 棘手的问题,请高手帮忙 求一JS框架源代码 请问能否用js来控制一个marquee的属性 script问题:动态生成的图片为什么不能onclick="window.open('projectlist.jsp')"呢? 关于<tr>高亮的一个问题 Uploadify 能否用JS来设定上传路径? 如何单击生成KindEditor automation服务器不能创建对象 jQuery.getJSON(),二级域名取不到数据
滑动切换 。
每次执行函数的时候用一个变量记住当前打开的对象
下次执行的时候让上一个打开的div关闭即可(思路很重要哦)
写个例子
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>NoName</title>
<style>
*{padding:0;margin:0;font-size:12px;}
.testDiv{width:198px;height:100px;border:1px solid #ccc;margin:0 0 5px 5px;display:none;}
h5{background:#ccc;width:200px;margin:5px 0 0 5px;height:24px;line-height:24px;cursor:pointer;}
</style>
<script>
var lastObj='';
function ShowMe(obj){
var ShowObj=document.getElementById(obj);
ShowObj.style.display=(ShowObj.style.display=='block')?'none':'block';
if (lastObj!='') lastObj.style.display='none';
lastObj=ShowObj;
}
</script>
</head><body>
<h5 onclick="ShowMe('Div1')">模块1</h5>
<div id="Div1" class="testDiv">
第一个栏目
</div>
<h5 onclick="ShowMe('Div2')">模块2</h5>
<div id="Div2" class="testDiv">
第二个栏目
</div>
<h5 onclick="ShowMe('Div3')">模块3</h5>
<div id="Div3" class="testDiv">
第三个栏目
</div>
</body>
</html>
function show(val)
{
for(var i = 1 i < 4; i++)
{
if(val == i)
{
$("#div" + i).show();
}
else
{
$("#div" + i).hide();
}
}
}<h5 onclick="ShowMe('2')">模块2</h5>
//给所有的增加一个class,比如:class="tip",然后
<script>
$(function(){
$(".tip").click(function(){
$(".tip").slideUp(500);
$(this).slideDown(500);
})
})
</script>
<div style="display:none/block">
......
......
</div>
通过改变display的属性值,none为不显示,block块状显示也可以使用插件:jQuery中有现成的,可以去找找