douqu2712 2012-12-04 13:02
浏览 59
已采纳

jQuery下拉菜单不会出现

I am trying to make a drop-down menu using jQuery/JavaScript, but my menu won't show anything.

Here is my code:

JavaScript:

function toggleMenu(target){
    if($(target).css("display")=='none'){
        $("#drop_down, drop_menu").hide(500);
    $(target).toggle(500);
}

header.php

<?php

?>
<div id="header" class="absolute" >
    <ul>
        <li class="float_left"><p class="pointer" onclick="toggleMenu('#drop_search')">Search</p></li>
        <li class="float_left"><p class="pointer" onclick="toggleMenu('#drop_login')">Log in</p></li>
        <li class="float_left"><p class="pointer" onclick="toggleMenu('#drop_chart')">My Cart</p></li>
        <li class="float_left"><p class="pointer" onclick="toggleMenu('#drop_menu')">Menu</p></li>
    </ul>
     <div class="clear_both"></div>
     <br/>    
    <div id="drop_down"class="right">
        <div id="drop_search" class="hidden">
            <p>Search</p>
        </div>
        <div id="drop_login" class="hidden">
            <p>login</p>
        </div>
        <div id="drop_chart" class="hidden">
            <p>cart</p>
        </div>
        <div id="drop_menu" class="hidden">
            <p>menu</p>
        </div>
    </div>
</div>

sorry for the long css, i just like to pack it into one file

style.css

body{
    position: relative;
    width: 100%;
    height: 100%;
    margin: 0px;
    padding: 0px;
    font-family: sans-serif;
}
body table{
    border-collapse: collapse;
    width: 100%;
}
body th, body tr, body td{
    padding: 0;
}
body h1, body h2,body h3,body h4,body h5,body h6,body p{
    margin: 0px;

}
body p{
    font-size: 12px;
}
body h6{
    font-size: 14px;
}body h5{
    font-size: 16px;
}body h4{
    font-size: 18px;
}body h3{
    font-size: 20px;
}body h2{
    font-size: 24px;
}body h1{
    font-size: 28px;
}
body ul,body li{
    list-style: none;
    margin: 0px;
    padding: 0px;
}
body img{
    border: none;
}
body hr{
    margin: 0px;
    border: none;
    height: 1px;
}
body a:link{
    text-decoration: none;
}
body a:visited{}
body a:hover{}
body .relative{
    position: relative;
}
body .absolute{
    position: absolute;
}
body .fixed{
    position: fixed;
}
body .float_left{
    float: left;
}
body .float_right{
    float: right;
}
body .clear_both{
    clear: both;
}
body input, body select, body textarea{
    border-radius: 5px;
}
body .input_text{}
body .input_select{
    border-radius: 5px;
    font-size: 11px;
}
body .input_option{
    background-color: #f6f6f6;
    color: #333333;
}
body .input_option_inactive{
    background-color: #f6f6f6;
    color: #888888;
}
body .input_submit{
    background: url("../images/submit.png");
    border: none;
    font-weight: bold;
    color: #efefef;
    cursor: pointer;
    border-radius: 20px;
    height: 20px;
}
body .input_submit:hover{
    color: #ffffff;
    text-shadow: 0 0 3px #efefef;
}
body .input_submit_inactive{
    background: url('#');
    border:none;
}
body .input_submit_inactive:hover{
    color: #333333;
    text-shadow: 0 0 3px #434343;
}
body .input_textarea{}
body .top{
    vertical-align: top;
}
body .middle{
    vertical-align: middle;
}
body .bottom{
    vertical-align: bottom;
}
body .left{
    text-align: left;
}
body .center{
    text-align: center;
}
body .right{
    text-align: right;
}
body .spacer{
    width: 10px;
    height: 10px;
}
body .bold{
    font-weight: bold;
}
body .italic{
    font-style: italic;
}
body .strip{
    text-decoration: line-through;
}
body .hidden{
    display: none;
}
body .show{
    display: block;
}
body .pointer{
    cursor: pointer;
}
body .scroll-y{
    overflow-y: scroll;
}
#whole{
    width: inherit;
    height:100%; 
    margin-left: auto;
    margin-right: auto;
    vertical-align: top;
}
.black{color: #000000;}
.white{color: #ffffff;}
.red{color: #ff0000;}
.green{color: #00ff00;}
.blue{color: #0000ff;}
.yellow{color: #ffff00;}
.toska{color: #00ffff;}
.pink{color: #ff00ff;}

header.css

#header{
    right: 0;
    top: 0;
}
 #header li{ height: 20px;
    background: #960000;
}
#header li p{
    margin: 0 15px;
    color: #cccccc;
    height: 12px;    
    line-height: 20px;
    font-weight: bold;
}
#header li p:hover{
    color: #f6f6f6;
}
#header #drop_down{
    background: url('../images/black20.jpg');
}

Can anyone can help ?

  • 写回答

3条回答 默认 最新

  • douzhan1935 2012-12-05 22:28
    关注

    You have a sintaxe error in your function
    Try with this function

    function toggleMenu(target){
        if($(target).is(":hidden")){
            $("#drop_down div").hide(500);
        }
        $(target).toggle(500);
    }
    

    And give me some feedback...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法