(function($){
    $.fn.fixedMenu=function()
{
        return this.each(function(){
            var menu= $(this);
            menu.find('ul li > a').bind('click',function()
{
            if ($(this).parent().hasClass('active'))
{

                $(this).parent().removeClass('active');
            }
            else
{
              
                $(this).parent().addClass('active');

            }

              }
)
        }


);


 
    }
})(jQuery);
这是jquery代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <script type="text/javascript" src="jquery-1.4.2.min.js"></script>
        <script type="text/javascript" src="jquery.fixedMenu.js"></script>
        <link rel="stylesheet" type="text/css" href="fixedMenu_style2.css" />
        <script>
        $('document').ready(function(){
            $('.top_nav_left').fixedMenu();
        });
         
 
        </script>
     <script type="text/javascript">
var obj=document.getElementById('s');function hide(){obj.style.display='none';}
function show(){obj.style.display='block'
}</script>    </head>
    <body>
    <div class="top_nav_left">
   <ul>         <li>
                 <a class="s"> wwwwww<span class="arrow"></span></a>
              <ul id="s">
            <li><a href="#">Plugins and jQuery Examples</a></li>
                    <li><a href="#">Prototype Examples</a></li>
                    <li><a href="#">Mootools Examples</a></li>
                    <li><a href="#">Javascript Examples</a></li>
                </ul>
            
            
  </li>
        </ul>
    </div>    </body>
</html>
这是html代码
body{
    padding:0;
    margin:0;
}
.top_nav_left{
      font: 13px/27px Arial,sans-serif;      color:#FFFFFF;
      height:30px;
      background: black;
}
.top_nav_left a:hover{
    background-color:#4C4C4C;
    color:#FFFFFF;}
.top_nav_left a {
    text-decoration: none;
    padding: 6px 8px 7px;
    color:white;
    outline:none;
}
.top_nav_left ul{
    list-style: none;
    margin:0;
    padding:0 0 0 10px;
}
.top_nav_left ul li{
    padding:0;
    float:left;
    
}
.top_nav_left ul li ul li{
    padding:0;
    float:none;
    margin: 0 0 0 0px;
    width:100%;
}
.top_nav_left ul li ul{
    position: absolute;
    border: 1px solid #C3D1EC;
    box-shadow: 0 1px 5px #CCCCCC;
    margin-top: -1px;
    display:none;
    padding: 0px 16px 0px 0;
}
.top_nav_left .active ul{
    display:block !important; 
}
.top_nav_left .active a{
    background-color: white;
    border: 1px solid #C3D1EC;
    border-bottom: 0;
    box-shadow: 0 -1px 5px #CCCCCC;
    display: block;
    height: 29px;
    padding: 0 8px 0 8px;
    position:relative;
    z-index: 1;
    color:#3366CC;}
.top_nav_left .active a:hover{
    background-color:white;
}
 .top_nav_left .active ul a:hover{
    background-color:#e4ebf8;
}.top_nav_left .active ul a{
    border: 0 !important;
    box-shadow: 0 0 0 #CCCCCC;
    border:0;
    width: 100%;
}
.top_nav_left .arrow {
    border-color: white transparent transparent;
    border-style: solid dashed dashed;
    margin-left: 5px;
    position: relative;
    top: 10px;
}这是css代码  
怎么样实现下点击其他地方下拉菜单关闭

解决方案 »

  1.   


    (function($) {
    $.fn.fixedMenu = function() {
    return this.each(function() {
    var menu = $(this);
    menu.find('ul li > a').bind('click', function() {
    if (menu.find('li:first').hasClass('active')) {
    menu.find('li:first').removeClass('active');
    }
    else {
    menu.find('li:first').addClass('active');
    }

    })



    });
    }
    })(jQuery);你的哪个选择的li 错误,应该去掉的时第一个li的class="active"