我對我的問題和答案頁面使用了點擊/隱藏功能。但是當我點擊問題來顯示答案時,它會跳回頂部。我需要做些什麼才能停止。jQuery中的顯示/隱藏功能問題。跳轉到頁面頂部
這是我的編碼:
腳本:
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery(".sub").hide();
//toggle the componenet with class msg_body
jQuery(".cthrough").click(function()
{
jQuery(this).next(".sub").slideToggle(500);
});});
</script>
CSS:
.cthrough {
display: inline-block;
font-size: 15px;
font-family: 'Anaheim', sans-serif;
text-transform: uppercase;
letter-spacing: 0px;
}
.sub {
display: inline-block;
font-size: 13px;
padding-left: 10px;
}
HTML:
<a href="#" class="cthrough">This is my question</a>
<div class="sub">
This is my answer.
</div>
我試圖在href =#轉換爲只是一個div類,但那個doe不要讓問題點擊。我也嘗試過#但沒有幫助。
沒有重複,但相關的話題:http://stackoverflow.com/questions/134845/href-attribute-for-javascript-links -or-javascriptvoid0/138233#138233 –