1. 程式人生 > >Boostrap導航欄跳轉到其他頁面或外部鏈接

Boostrap導航欄跳轉到其他頁面或外部鏈接

target 之前 ref type navbar tar 設置 pre www.

想要在boostrap下增加一個標簽a,並設置其href屬性來實現跳轉功能(具體是想在導航欄中添加,點擊某個導航欄部件時跳轉至其他頁面),但是發現事情並不是想象中的那麽簡單;

“Bootstrap為這些a之類元素都綁定上了事件,而終止了鏈接默認行為。”(https://stackoverflow.com/questions/16785264/jquery-syntax-error)

data-toggle : 標記用於觸發的;
data-dismiss:標記點擊後消失;
data-target:一般用於button標簽裏面,後面的參數是響應的標簽對應的ID

(https://www.jianshu.com/p/6c2f589ab1a0)

直接加個onclick=……

具體見下面代碼2行

1 <ul class="nav navbar-nav navbar-right">
2      <li><a data-toggle="modal" data-target="#register" onclick="window.location.href=‘index1.html‘"><span class="glyphicon glyphicon-user"></span> 註冊</a></li>
3      <li><a data-toggle
="modal" data-target="#login" id="loging" href=""><span class="glyphicon glyphicon-log-in"></span> 登錄</a></li> 4 </ul>

或者使用一個js來處理

1 <script type="text/javascript">
2         $(function($) {
3             // 登錄點擊
4             $("#loging").click(function() {
5                 //
window.location.href = "https://www.xiami.com/collect/358371983";(跳轉至外部鏈接) 6 window.location.href =‘index1.html‘; 7 }); 8 }); 9 </script>

最後提醒一下:

jquery庫的引用一定要在bootstrap庫之前,因為bootstrap依賴jquery庫工作。

自己在這上面吃過虧。

Boostrap導航欄跳轉到其他頁面或外部鏈接