我正在开发一个 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/