zoukankan      html  css  js  c++  java
  • bootsrap+jquery+组件项目引入文件的常见报错

    做一个项目的时候 ,控制台总是会出现各种bug,其实不用慌张,终结起来也就几种类型的错误,在开发中每次遇到错误都善于总结,下次在看到就会胸有成竹知道是什么情况了,以下是在开发过程中总结的一些错误以及错误的解决方法。

    报错一:Uncaught ReferenceError: $ is not defined

    Uncaught ReferenceError: $ is not defined
    Uncaught ReferenceError: jQuery is not defined
    
    5640239-43b8a13d432fdbd0.png
    图片.png

    错误原因:文件加载的顺序不对,jQuery文件的顺序要在前面


    5640239-dbe8289e152be550.png
    图片.png

    方法:把jQuery文件写在所有script文件前面


    5640239-fdb284822b761d50.png
    图片.png

    报错二:jsp页面相对路径和绝对路径的问题:

    正常路径:html里面的../../,改成jsp页面就找不到路径了,这个时候成了这个鬼样子

    5640239-6ac45ffcd66ab8ed.png
    图片.png

    这时候,只需要在文件里面加入这段代码:


    5640239-678de7cdb9c4cbcf.png
    图片.png

    解决办法:在<html>和<head>之间插入以下代码

    <%
        String path = request.getRequestURI();
        String basePath = request.getScheme() + "://"
                + request.getServerName() + ":" + request.getServerPort()
                + path;
    %>
    <base href="<%=basePath%>">
    

    报错三: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)
    
    5640239-4e63bf55e8696ad9.png
    图片.png

    原因:包括两个不同版本的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
    
    5640239-a593213f12ed788b.png
    图片.png

    解决方案:解决方案:将jquery.min.js放在bootstrap.min.js文件之前引用,bootstrap.min.css文件在整两个文件前后引用都无妨(测试多次)。

  • 相关阅读:
    1、向服务传送复杂的类型实例(服务端程序)(摘自ProAndroid2)
    我项目中用到的jquery+json+struts2
    JSON与JAVA的数据转换
    管理和组织首选项
    python中如何对dict对象进行排序
    python cx_Oracle模块的安装和使用(linux环境)
    python cx_Oracle模块的安装和使用(linux环境)
    django的一个小功能——SortedDict
    Linux中source命令的用法
    linux uname命令参数及用法详解linux查看系统信息命令
  • 原文地址:https://www.cnblogs.com/wangting888/p/9701850.html
Copyright © 2011-2022 走看看