bootstrap+jquery項目引入檔案報錯的解決方案,bootstrapjquery
做一個項目的時候 ,控制台總是會出現各種bug,其實不用慌張,終結起來也就幾種類型的錯誤,在開發中每次遇到錯誤都善於總結,下次在看到就會胸有成竹知道是什麼情況了,以下是在開發過程中總結的一些錯誤以及錯誤的解決方案。
報錯一:Uncaught ReferenceError: $ is not defined
Uncaught ReferenceError: $ is not definedUncaught ReferenceError: jQuery is not defined
錯誤原因:檔案載入的順序不對,jQuery檔案的順序要在前面
方法:把jQuery檔案寫在所有script檔案前面
報錯二:jsp頁面相對路徑和絕對路徑的問題:
正常路徑:html裡面的../../,改成jsp頁面就找不到路徑了,這個時候成了這個鬼樣子
這時候,只需要在檔案裡面加入這段代碼:
解決辦法:在<html>和<head>之間插入以下代碼
<% String path = request.getRequestURI(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path;%><base href="<%=basePath%>" rel="external nofollow" >
報錯三:Uncaught TypeError: $(...).tooltip is not a function
Uncaught TypeError: $(...).tooltip is not a function at HTMLDocument.<anonymous> (app.js:42) at l (jquery.min.js:4) at Object.fireWith [as resolveWith] (jquery.min.js:4) at Function.ready (jquery.min.js:4) at HTMLDocument.S (jquery.min.js:4)
原因:包括兩個不同版本的jQuery UI。這可能會導致衝突。嘗試刪除
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
解決辦法:
編輯:
<script>jQuery( document ).ready(function( $ ) { $('.hasTooltip').tooltip();});</script>
像這樣使用它,解決了我的問題!
報錯四:Uncaught TypeError: $(...).sortable is not a function
Uncaught TypeError: $(...).sortable is not a function at HTMLDocument.<anonymous> (dashboard.js:12) at l (VM552 jquery.min.js:4) at Object.fireWith [as resolveWith] (VM552 jquery.min.js:4) at Function.ready (VM552 jquery.min.js:4) at HTMLDocument.S (VM552 jquery.min.js:4)
報錯五:bootstrap.min.js:7 Uncaught Error: Bootstrap requires jQuery
bootstrap.min.js:7 Uncaught Error: Bootstrap requires jQuery at bootstrap.min.js:7
解決方案:解決方案:將jquery.min.js放在bootstrap.min.js檔案之前引用,bootstrap.min.css檔案在整兩個檔案前後引用都無妨(測試多次)。
總結
以上所述是小編給大家介紹的boostrap+jquery項目引入檔案報錯的解決方案,希望對大家有所協助,如果大家有任何疑問請給我留言,小編會及時回複大家的。在此也非常感謝大家對幫客之家網站的支援!