jQuery上载插件当我复制到本地计算机时不起作用

时间:2012-03-01 07:27:22

标签: javascript jquery

全部, 我正在使用以下jQuery插件: https://github.com/blueimp/jQuery-File-Upload

您可以在index.html文件中看到它调用此文件:

<script src="http://blueimp.github.com/JavaScript-Templates/tmpl.min.js"></script>

当我转到此URL尝试将代码复制到本地JS文件时,它看起来如下所示:

(function(a){"use strict";var b=function(a,c){var d=/[^\w\-\.:]/.test(a)?new Function(b.arg+",tmpl","var _e=tmpl.encode"+b.helper+",_s='"+a.replace(b.regexp,b.func)+"';return _s;"):b.cache[a]=b.cache[a]||b(b.load(a));return c?d(c,b):function(a){return d(a,b)}};b.cache={},b.load=function(a){return document.getElementById(a).innerHTML},b.regexp=/([\s'\\])(?![^%]*%\})|(?:\{%(=|#)([\s\S]+?)%\})|(\{%)|(%\})/g,b.func=function(a,b,c,d,e,f){if(b)return{"\n":"\\n","\r":"\\r","\t":"\\t"," ":" "}[a]||"\\"+a;if(c)return c==="="?"'+_e("+d+")+'":"'+("+d+"||'')+'";if(e)return"';";if(f)return"_s+='"},b.encReg=/[<>&"'\x00]/g,b.encMap={"<":"&lt;",">":"&gt;","&":"&amp;",'"':"&quot;","'":"&#39;"},b.encode=function(a){return String(a||"").replace(b.encReg,function(a){return b.encMap[a]||""})},b.arg="o",b.helper=",print=function(s,e){_s+=e&&(s||'')||_e(s);},include=function(s,d){_s+=tmpl(s,d);}",typeof define=="function"&&define.amd?define(function(){return b}):a.tmpl=b})(this);

当我更改index.html以查看我的本地副本时,它会给我一个未定义的错误,但如果我将它留在index.html上的URL,它可以正常工作。有什么想法会发生这种情况吗?

1 个答案:

答案 0 :(得分:3)

它不起作用,因为您在缩小的代码中缺少分号,您可以在JSHint.com检查以下美化代码。 您需要修复这些丢失的分号错误,以使其适合您。

(function (a) {
    "use strict";
    var b = function (a, c) {
            var d = /[^\w\-\.:]/.test(a) ? new Function(b.arg + ",tmpl", "var _e=tmpl.encode" + b.helper + ",_s='" + a.replace(b.regexp, b.func) + "';return _s;") : b.cache[a] = b.cache[a] || b(b.load(a));
            return c ? d(c, b) : function (a) {
                return d(a, b)
            }
        };
    b.cache = {}, b.load = function (a) {
        return document.getElementById(a).innerHTML
    }, b.regexp = /([\s'\\])(?![^%]*%\})|(?:\{%(=|#)([\s\S]+?)%\})|(\{%)|(%\})/g, b.func = function (a, b, c, d, e, f) {
        if (b) return {
            "\n": "\\n",
            "\r": "\\r",
            "\t": "\\t",
            " ": " "
        }[a] || "\\" + a;
        if (c) return c === "=" ? "'+_e(" + d + ")+'" : "'+(" + d + "||'')+'";
        if (e) return "';";
        if (f) return "_s+='"
    }, b.encReg = /[<>&"'\x00]/g, b.encMap = {
        "<": "&lt;",
        ">": "&gt;",
        "&": "&amp;",
        '"': "&quot;",
        "'": "&#39;"
    }, b.encode = function (a) {
        return String(a || "").replace(b.encReg, function (a) {
            return b.encMap[a] || ""
        })
    }, b.arg = "o", b.helper = ",print=function(s,e){_s+=e&&(s||'')||_e(s);},include=function(s,d){_s+=tmpl(s,d);}", typeof define == "function" && define.amd ? define(function () {
        return b
    }) : a.tmpl = b
})(this);