在jQuery中显示/隐藏功能的问题.跳到文档顶部

mic*_*urk 3 html javascript jquery show hide

我的网站上有2个基本的显示/隐藏链接,效果很好.

这是我的HTML:

<!DOCTYPE html>
<html lang="en">

<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<script type="text/javascript" src="http://codylindley.com/blogstuff/js/jquery/jquery-base.js"></script>
<script type="text/javascript">
$(document).ready(function(){

    $("input.buttonAsize").click(function(){ alert($("div.contentToChange").find("p").size()); });
    $("a.codeButtonA").click(function(){$("pre.codeA").toggle()});

    $("input.buttonBsize").click(function(){ alert($("div.contentToChange").find("p").size()); });
    $("a.codeButtonB").click(function(){$("pre.codeB").toggle()});

});
</script>

<style type="text/css">
pre {
background: white;
overflow: auto;
display:none;
}
</style>

</head>

<body>

    <a href="#" class="codeButtonA">Show / Hide</a>
    <pre class="codeA">
    test message 1
    </pre>

<div style="background:green;margin-top:1000px">
    <a href="#" class="codeButtonB">Show / Hide</a>
    <pre class="codeB">
    test message 2
    </pre>
</div>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

但是,当我单击页面底部的第二个链接时,它打开<pre>标记,但随后会跳转到页面顶部.当我点击它时,有没有办法阻止它跳到页面顶部?

我更喜欢它只是显示盒子而从未跳到顶部.

非常感谢您对此的任何帮助.

Tim*_*ote 9

或者href="#"<A>标签中删除