Jquery显示函数问题 - 没有动画或显示隐藏段落,为什么

时间:2011-01-15 01:49:36

标签: jquery animation show

这是html:

<html xmlns="http://www.w3.org/1999/xhtml">                                                                 
<head>                                                                  
    <script src="http://code.jquery.com/jquery-1.4.4.js"></script>
    <link rel = "stylesheet" type = "text/css" href = "sample1.css"></link>       
    <script type="text/javascript">
        $(document).ready(function() { 
            $("#testing").click(function() { 
                $("#testing2").show("slow");  
            });
        });  
    </script>                                                                  
</head>                                                                 
<body>                                                                   
    <a id = "testing" href="">Link</a>      
    <p id = "testing2"> 
        lksjflksjdlkflskdjflksjdflkjslkjdflk
        lsdkflksjgliowtjlskdfjlskdfjlskgs
        lksjlk,.x,cmlkvjlkjlwkeoltklfnjsklkj
        lksjf.m,.jlkjoliwekjtlkjgkjjlkjlkjll
        llvalkiwujoitjlkgskjdkgjlsd,fjlsllll
    </p>
</body>                                                                 
</html> 

这是css:

#testing
{
    width:          100px;
    height:         50px;
    border:         1px solid;
    font-size:      22px;
    display:        block;
    text-align:     center;
    padding:        25px 0px 0px 0px;
}

#testing2
{
    display:        none; 
    width:          270px;
    height:         300px;
    background:     yellow;
    border:         1px solid;
}

出于某种原因,当我点击链接时,它没有显示段落#testing2,为什么?

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

尝试将return false;放入点击功能中。作为良好的做法,您应该链接到#eg href =“#”以及

$(document).ready(function(){ 
    $("#testing").click(function(){ 
       $("#testing2").show("slow");
       return false;
    });
});