簡體   English   中英

javascript執行后,點擊頁面跳來跳去

[英]page jumping around on click after javascript execution

我有一個JavaScript(jquery)代碼段,該代碼段鏈接到href =“#”來切換點擊。當我在頁面上單擊時,一切都很好,所有內容都被復制了……我希望頁面停留在該位置這是...返回false什么也沒做...

這是代碼:

<script type="text/javascript"> 
 jQuery(document).ready(function(){
  jQuery('#social li').click(function(){
   button = jQuery(this).attr('class');
   switch (button)
    { 
    case 'social1' : 
    jQuery('#facebookbox').show(); 
    jQuery('#twitterbox').hide();
    jQuery('.social1 a').addClass('selected');
    jQuery('.social2 a').removeClass('selected');
    break;

    case 'social2' : 
    jQuery('#facebookbox').hide(); 
    jQuery('#twitterbox').show(); 
    jQuery('.social2 a').addClass('selected');
    jQuery('.social1 a').removeClass('selected');
    break;
    }
  });
}); 
</script>

使其鏈接到不存在的錨,例如href =“ #_”

您可以將href設置為href =“ javascript:void(0)”。 那應該防止它跳來跳去。 確保在onclick事件中返回false,否則您可能在IE6中遇到問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM