2016-03-18 86 views
0

當我點擊一個鏈接(一個href)時,只會出現背景加載器。但是定義的鏈接沒有打開,屏幕在加載器屏幕上出現。在這個屏幕上,我無法訪問任何功能。我已經嘗試了幾個星期,但沒有積極的結果。請幫我找到了錯誤的添加值編碼javascript - 我的鏈接無法打開另一個鏈接

$(document).ready(function() { 
 
    var loading = $('<div>').prop('id', 'loading'); 
 
    loading.html('<div id="stretch"></div><img src="assets/img/ring.gif" style="repeat:no-repeat;" /> Loading...'); 
 

 
    //FOR TESTING   
 
    //alert( loading.text()); //FOR TESTING ONLY!!! 
 
    $("#cmd").click(function() { 
 
     loading.appendTo('body'); 
 

 
     var event = $(document).click(function(e) { 
 
      e.stopPropagation(); 
 
      e.preventDefault(); 
 
      e.stopImmediatePropagation(); 
 
     }); 
 

 
     // disable right click 
 
     $(document).bind('contextmenu', function(e) { 
 
      e.stopPropagation(); 
 
      e.preventDefault(); 
 
      e.stopImmediatePropagation(); 
 
     }); 
 
    }); 
 
});;
#loading { 
 
    background-color: white; 
 
    background-color: rgba(1, 1, 1, 0.7); 
 
    bottom: 0; 
 
    left: 0; 
 
    position: fixed; 
 
    right: 0; 
 
    text-align: center; 
 
    top: 0; 
 
} 
 

 
#loading * { 
 
    vertical-align: middle; 
 
} 
 

 
#stretch { 
 
    display: inline-block; 
 
    height: 100%; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<li><a href="http://www.google.com/" id="cmd" ><i class="glyphicon glyphicon-tags"></i>Application</a></li>

+0

你的html看起來像什麼? – whipdancer

回答

1

當然,當你停止觸發(點擊)默認事件時,它並沒有做任何事情。

e.preventDefault(); 

這可以防止發生默認操作。但是,當您使用Javascript加載第三方網站時,您會遇到問題。