开发者社区> 问答> 正文

帮我看下面jquery代码有什么问题,谢谢

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<style type="text/css">
        #menu{width:300px;}
        .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;floar:left;width:300px;}
</style>
<script src="jquery-1.7.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function(){
        alert("hello world!");
    });
    $(".has_children").click(function(){
        $(this).addClass("highlight").children("a").show().end().siblings().removeClass("highlight").children("a").hide();
    });
</script>
</head>
<body>
    <div id="menu">
        <div class="has_children">
            <span>第一章</span>
            <a>1</a>
            <a>2</a>
            <a>3</a>
            <a>4</a>
            <a>5</a>
        </div>
        <div class="has_children">
            <span>第二章</span>
            <a>21</a>
            <a>22</a>
            <a>23</a>
            <a>24</a>
            <a>25</a>
        </div>
    </div>
</body>
</html>

展开
收起
a123456678 2016-07-07 14:41:27 1669 0
1 条回答
写回答
取消 提交回答
  • $(".has_children").click(function(){ $(this).addClass("highlight").children("a").show().end().siblings().removeClass("highlight").children("a").hide(); }); 你这个js放在位置根本不会起作用呢! $(document).ready(function(){ 应该放到这个里面! });
    2019-07-17 19:52:48
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
相关产品:
问答排行榜
最热
最新

相关课程

更多

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载