下面这段jquery写的导航页面,为什么点了has_children类定义的div里面的标题
没有反应阿?正常的情况下面,应该弹出一个警告窗口的<html>
<head>
<title></title>
<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;float:left;width:300px;}
</style>
<script src="jquery-1.6.2.js" type="text/javascript">
</script>
<script type="text/javascript">
$(".has_children").click(
function(){
alert("0");
}
);
</script>
</head>
<body>
<div id="menu">
<span>第一章-认识jQuery</span>
<a>1.1-JavaScript和JavaScript库</a>

<div class="has_children">
<span>第二章-jQuery选择器</span>
<a>2.1-jQuery选择器是什么</a>
</div>

<div class="has_children">
<span>第三章-jQuery中的DOM操作</span>
<a>3.1-DOM操作的分类</a>
</div>
</div>
</body>
</html>

解决方案 »

  1.   


    <script type="text/javascript">
    jQuery(function($) {
      $(".has_children").click(function(){
        alert("0");
      });
    });
    </script>放到页面载入后事件里面去 。
      

  2.   

    你的
    $(function(){});呢
    你的代码应该放在上面代码中执行!相当于JS中window.onload()
      

  3.   

    $(function(){
    $(".has_children").click(
        function(){
        alert("0");
        }
    );});

    $(document).ready(function(){
    $(".has_children").click(
        function(){
        alert("0");
        }
    );});