0

我不知道这是否可能。我有一个 jquery 下拉菜单,当我单击幻灯片菜单中的一个链接时,我不希望滑块关闭。当我到达点击链接的目标页面时,我希望它保持打开状态。

这是我的代码:index.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Advice center</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-5">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){
        $("#flip_1").click(function(){
            $("#panel_1").slideToggle("slow");
        });
    });
</script>

<style type="text/css">
.nodisplay{
 display:none; 
}
</style>
</head>
<body>
<ul>
    <li><a href="page1.html">Page 1</a></li>
    <li><a href="page2.html">Page 2</a></li>
    <li><a href="page3.html">Page 3</a></li>
    <li><a href="page4.html">Page 4</a></li>

    <li id="flip_1"> <span>Slide here</span></li>
        <div id="panel_1" class="nodisplay">
            <ul>
                <li><a href="section1.html">section 1</a></li>
                <li><a href="section2.html">section 2</a></li>

              </ul> 
        </div>  

       <li><a href="">bottom 1</a></li>
       <li><a href="">bottom 2</a></li>
     </ul>
</body>
</html>

这是链接到section1.html的页面之一

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Advice center</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-5">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){
        $("#flip_1").click(function(){
            $("#panel_1").slideToggle("slow");
        });     
       });
</script>

<style type="text/css">
.nodisplay{
 display:none; 
}
</style>

</head>

<body>

<ul>
    <li><a href="page1.html">Page 1</a></li>
    <li><a href="page2.html">Page 2</a></li>
    <li><a href="page3.html">Page 3</a></li>
    <li><a href="page4.html">Page 4</a></li>

    <li id="flip_1"> <span>Slide here</span></li>
        <div id="panel_1" class="nodisplay">
            <ul>
                <li><a href="section1.html">section 1</a></li>
                <li><a href="section2.html">section 2</a></li>

              </ul> 
        </div>  

       <li><a href="">bottom 1</a></li>
       <li><a href="">bottom 2</a></li>
     </ul>

Welcome to section 1
</body>
</html>

第三页如下:section2.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Advice center</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-5">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){
        $("#flip_1").click(function(){
            $("#panel_1").slideToggle("slow");
        });

    });
</script>

<style type="text/css">
.nodisplay{
 display:none; 
}
</style>

</head>

<body>

<ul>
    <li><a href="page1.html">Page 1</a></li>
    <li><a href="page2.html">Page 2</a></li>
    <li><a href="page3.html">Page 3</a></li>
    <li><a href="page4.html">Page 4</a></li>

    <li id="flip_1"> <span>Slide here</span></li>
        <div id="panel_1" class="nodisplay">
            <ul>
                <li><a href="section1.html">section 1</a></li>
                <li><a href="section2.html">section 2</a></li>

              </ul> 
        </div>  

       <li><a href="">bottom 1</a></li>
       <li><a href="">bottom 2</a></li>
     </ul>

This is section 2 (TWO) page
</body>
</html>
4

2 回答 2

0

Try the following if one of your links is clicked (you'll need an if/else in your .click event binding):

$("#panel_1").stop();
于 2011-09-15T13:22:47.647 回答
0

On the inner links, use a hash to identify them

<a href="section1.html#panel">Section 1</a>

Then onPageLoad you can check if there's a hash and use this to open:

if(window.location.hash == "#panel") $("#panel_1").slideDown();

Also, a small fix to your code: put that div inside the li

<li id="flip_1"><span>Slide here</span>
    <div id="panel_1" class="nodisplay">
        <ul>
            <li><a href="section1.html">section 1</a></li>
            <li><a href="section2.html">section 2</a></li>
        </ul> 
    </div> 
</li>

And then use this to toggle:

$("#flip_1 span").click(function(){
        $("#panel_1").slideToggle("slow");
});
于 2011-09-15T13:23:30.177 回答