为什么这样写没有什么作用呢?好烦啊,找不到哪里错了
jquery吧
全部回复
仅看楼主
level 2
代码不知道哪里错了,想实现导航器的那种效果的,点击一下,会把下面的细项展示出来的,但是不知道为什么点了没反应
2015年08月27日 15点08分 1
level 2
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="../js/jquery-1.9.1.js" type="text/javascript" language="javascript"></script>
<title>1-9</title>
<style type="text/css">
#menu{width:100px;}
.has_children{background:#555;color:#fff;cursor:pointer;}
.highlight{color:#fff;background:green;}
div{padding:0; margin:10px 0;}
div a {background:#888;display:none;float:left;width:300px;}
</style>
<script type="text/javascript">
$(".has_children").click(function(){
alert("");
$(this).addClass("highlight")
.children("a").show().end()
.siblings().removeClass("highlight")
.children("a").hide();
});
</script>
</head>
<body>
<div id="menu">
<div class="has_children">
<span>A</span>
<a>a1</a>
<a>a2</a>
<a>a3</a>
<a>a4</a>
<a>a5</a>
</div>
<div class="has_children">
<span>B</span>
<a>b1</a>
<a>b2</a>
<a>b3</a>
<a>b4</a>
<a>b5</a>
</div>
<div class="has_children">
<span>C</span>
<a>c1</a>
<a>c2</a>
<a>c3</a>
<a>c4</a>
<a>c5</a>
</div>
</div>
</body>
</html>
2015年08月27日 15点08分 2
level 5
.hide这句去掉试试
2015年08月28日 00点08分 3
$(this).addClass("highlight") .children("a").show().end() .siblings().removeClass("highlight"); }); 改成这样吗?没有用,连Click都进不去,这是为什么?我确定不是导入js路径的问题的
2015年08月28日 01点08分
end也去掉
2015年08月28日 06点08分
$(".has_children").click(function(){ alert("123"); }); 我像这样写,连alert都进不去,根本没进这个function里面去,[泪]
2015年08月28日 09点08分
我只想默默的说一句,你们眼神能仔细一点么
2015年08月28日 09点08分
level 5
<!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=UTF-8">
<script type="text/javascript" src="js/jquery-1.8.2.min.js"></script>
<title>1-9</title>
<style type="text/css">
#menu{width:100px;}
.has_children{background:#555;color:#fff;cursor:pointer;}
.highlight{color:#fff;background:green;}
div{padding:0; margin:10px 0;}
div a {background:#888;display:none;float:left;width:300px;}
</style>
<script type="text/javascript">
$(function(){
$(".has_children").click(function(){
alert("");
$(this).addClass("highlight")
.children("a").show().end()
.siblings().removeClass("highlight")
.children("a").hide();
});
})
</script>
</head>
<body>
<div id="menu">
<div class="has_children">
<span>A</span>
<a>a1</a>
<a>a2</a>
<a>a3</a>
<a>a4</a>
<a>a5</a>
</div>
<div class="has_children">
<span>B</span>
<a>b1</a>
<a>b2</a>
<a>b3</a>
<a>b4</a>
<a>b5</a>
</div>
<div class="has_children">
<span>C</span>
<a>c1</a>
<a>c2</a>
<a>c3</a>
<a>c4</a>
<a>c5</a>
</div>
</div>
</body>
</html>
2015年08月28日 09点08分 4
你这样写,也没用啊
2015年08月28日 15点08分
我把你的复制过去的,也没用啊
2015年08月28日 15点08分
说错了,有用的,对的,抱歉,js的包我没看到,一定要加function吗?
2015年09月01日 01点09分
你用的是jq 必须写,这没有商量的余地,这个其实就是相当于js 中的load
2015年09月01日 08点09分
level 5
留个邮箱,我发你个类似的,你参考一下
2015年08月28日 15点08分 5
level 5
我扣扣715560471
2015年08月28日 15点08分 6
level 3
问题可以去相关论坛(联动北方)提问,会有专家解答[勉强]
2015年08月31日 09点08分 7
level 2
[滑稽]根本没遍历,怎么可能执行,更何况动作不要写在最外层大框架上,这样会导致误操作,可以写在span上执行动作,然后点击一次展开第二次关闭不要用end,可以选择toggle,当然前提是jquery的版本不要太高,要不toggle会失效,我基本还停留在1.7.2呢
js部分改动:
<script type="text/javascript">
$(function(){
$(".has_children").each(function(){
$(this).find("span").toggle(function(){
$(this).parent(".has_children").addClass("highlight").find("a").show();
},function(){
$(this).parent(".has_children").removeClass("highlight").find("a").hide();
});
});
});
</script>
css部分加一个
.has_children span{display:block;}
就可以了
2015年09月08日 09点09分 8
谢谢,我回去试试看[真棒]
2015年09月09日 01点09分
1