簡體   English   中英

在單個文件中合並jquery-1.9.1.min.js和query.mobile-1.3.0.min.js會給出錯誤

[英]merge jquery-1.9.1.min.js and query.mobile-1.3.0.min.js in a single file give error

我正在開發一個jQuery移動Web應用程序

基本結構需要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文件的末尾),頁面就會停止工作和螢火蟲給我一個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看起來像傳遞給第一個的論點。 因此它失敗了。 添加分號解決了該問題,因為它指定了這兩個語句。

JavaScript中的分號是可選的,但是忽略它們非常危險。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM