javascript - 将 jquery-1.9.1.min.js 和 jquery.mobile-1.3.0.min.js 合并在一个文件中会出现错误

标签 javascript jquery jquery-mobile

我正在开发一个 jquery 移动网络应用程序

基本结构需要 jqueryMobile 文档中记录的 jquery.js 和 jquery-mobile.js 广告。

<!DOCTYPE html> 
<html>
<head>
    <title>Page Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" />
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="myjqueryconfig.js"></script>
    <script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
</head>

在这种结构下一切都很好,但我想将 jquery js 文件与 jquery-mobile js 文件合并以获得一个 js 文件,但是当我这样做时(只需将 jquery mobile 代码剪切并推到 jquery 文件的末尾)页面停止工作并且 firebug 给我一个 javascript 错误:

   TypeError: $(...).bind(...) is not a function

我的单个 .js 文件的结构如下:

//jquery 1.9.1 min source code

$(document).bind("mobileinit", function(){
    $.mobile.autoInitializePage = false
})

//jquery mobile min 1.3.0 source code

最佳答案

连接文件时在文件之间添加 ; 可以解决问题。

看看这段代码:

(function(){
  console.log('A');
}())

(function(){
  console.log('B');
}())

如果没有中间分号,第二个 IIFE 看起来就像传递给第一个 IIFE 的参数。所以它失败了。添加分号可以解决问题,因为它指定这是两个语句。

JavaScript 中的分号是可选的,但省略它们是非常危险的。

关于javascript - 将 jquery-1.9.1.min.js 和 jquery.mobile-1.3.0.min.js 合并在一个文件中会出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15273329/

相关文章:

javascript - Google map - 删除以前的标记

javascript - 以编程方式添加数组的对象属性

javascript - Axios API get request with Redux not able to pass in variable in action

javascript - 使用 jQuery 将 img 元素复制到另一个 div

javascript - 运行存储在变量中的 jQuery 函数

javascript - 移动滚动方向检测溢出 : hidden page

javascript - 更改点击事件中选定的选项卡

javascript - 通过 ajax 为 flot.js 提供的数据表示未定义

django - jquery 移动和动态页面内容

jquery - 使用 jquery 拖放更改 div 的位置