[英]jquery toggle… jumps to top of page
I'm using this script that I found on JS fiddle: http://jsfiddle.net/Q4PUw/2/ 我正在使用在JS小提琴上找到的此脚本: http : //jsfiddle.net/Q4PUw/2/
When I click on the toggle link, it toggles the box and displays it, however, it jumps back to the top of the page, and then I have to scroll down again to view the content that has been toggled. 当我单击切换链接时,它切换并显示该框,但是,它跳回到页面顶部,然后我必须再次向下滚动才能查看已切换的内容。
What can I do to keep the page on that content so that users don't have to scroll down again to view the content? 我该怎么做才能将页面保留在该内容上,以使用户不必再次向下滚动即可查看该内容?
Here is my code: 这是我的代码:
<style type="text/css">p.content-one {display:none;}</style>
<script type="text/javascript">//<![CDATA[
$(window).load(function(){
$('.expand-one').click(function(){
$('.content-one').slideToggle('slow');
});
});//]]>
</script>
<div class="sitesection">
<p class="expand-one"><a href="#">Toggle Test Here</a></p>
<p class="content-one">
The content goes here
</p>
</div>
remove href="#" in <a> tag
要么
If you dont want, remove a tag because you are using expand-one class in p tag
Try using event.preventDefault()
as shown :- 尝试使用
event.preventDefault()
,如下所示:
$('.expand-one').click(function(event){
event.preventDefault();
$('.content-one').slideToggle('slow');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.