我不知道这是否可行。我有一个jquery slidedown菜单,当我点击幻灯片菜单中的一个链接时,我不希望滑块关闭。当我到达点击链接的目标页面时,我希望它保持打开状态。
这是我的代码: 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>
答案 0 :(得分:0)
如果点击了您的某个链接,请尝试以下操作(您的.click事件绑定中需要if / else):
$("#panel_1").stop();
答案 1 :(得分:0)
在内部链接上,使用哈希来识别它们
<a href="section1.html#panel">Section 1</a>
然后onPageLoad
你可以检查是否有哈希并使用它来打开:
if(window.location.hash == "#panel") $("#panel_1").slideDown();
此外,对您的代码进行了一些小修复:将该div放在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>
然后用它来切换:
$("#flip_1 span").click(function(){
$("#panel_1").slideToggle("slow");
});