jQuery 压缩导致错误

发布于 2024-08-29 06:49:14 字数 620 浏览 3 评论 0原文

有人可以解释一下当我有一个运行良好且没有错误的 jquery 脚本时,然后压缩并上传它然后返回错误吗?

非常感谢。

编辑我使用 jsLint 遇到的唯一错误是:

错误:

隐含全局:$ 3,25,27,28,31,32,34,35,36,38,45,46,47,49,50,61,63, 64,65,67,71,75,79,83,87,91,94,95,96,98,101,102,103,111,113,114,115,121,123,124,125,127,130,131,132,142,144,145,146,147,148,149,150,151,152,153,154,155,171,173,174,175,177,180,181,182,192,194,195,196,197,198,199,200,201,202,214,216,217,218,220,223,224,225,234,240,241,242,243,244,245,246,247,248,249,250,251,253,254,255,256,257,258,259,260, window 7, alert 56,106,137,187,230, document 234

which is cause its in jQuery im guessing

could someone please explain when I have a jquery script which runs fine with no errors and then compress and upload it then returns errors?

Much appreciated.

EDIT The only error im getting using jsLint is:

Error:

Implied global: $ 3,25,27,28,31,32,34,35,36,38,45,46,47,49,50,61,63,64,65,67,71,75,79,83,87,91,94,95,96,98,101,102,103,111,113,114,115,121,123,124,125,127,130,131,132,142,144,145,146,147,148,149,150,151,152,153,154,155,171,173,174,175,177,180,181,182,192,194,195,196,197,198,199,200,201,202,214,216,217,218,220,223,224,225,234,240,241,242,243,244,245,246,247,248,249,250,251,253,254,255,256,257,258,259,260, window 7, alert 56,106,137,187,230, document 234

which is cause its in jQuery im guessing

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

淡淡绿茶香 2024-09-05 06:49:14

您很可能在某些行缺少语句终止符 ; ,例如,即使我没有指定以下代码也可以正常运行:

$(....).click(function(){
  .....
}) <-- // no `;` char here

或者甚至是这样:

alert('hello') <-- // no `;` char here

但是当您压缩它时,并且如果您忘记将该字符放置在某处,您将收到错误消息。

除了任何可能的问题之外,请确保您的脚本中没有出现这种情况。

Most likely you are missing the statement terminator ; at some line(s), for example following code would run fine even if i don't specify that:

$(....).click(function(){
  .....
}) <-- // no `;` char here

Or even this:

alert('hello') <-- // no `;` char here

But when you compress it, and you have forgot to place that character somewhere, you will receive the errors.

Make sure this is not the case in your script other than any possible issue.

可爱咩 2024-09-05 06:49:14

可能是因为脚本中存在错误,但在脚本未压缩时不会导致任何问题。

我建议尝试在脚本上使用 jslint 来验证它是否正确。

Probably because you have errors in your script that does not cause any problems when the script is not compressed.

I recommend try using jslint on the script to verify that it is correct.

睫毛溺水了 2024-09-05 06:49:14

JSLint 的替代方案是 JavaScriptLint。也许也值得检查一下。您在浏览器中遇到什么错误? Firefox 的 Firebug 应该会为您提供有关错误消息的更多详细信息。

An alternative to JSLint is JavaScriptLint. May be worth checking it in that too. What errors are you getting in the browser? Firebug for Firefox should give you more details of the error message.

贱贱哒 2024-09-05 06:49:14

我不确定您使用什么来压缩 JavaScript,但我在使用 Google Closure 编译器时注意到它本身并不遵循“规则”。

给出这段代码:

var t = true;
if (t) { alert("it's true!"); }

在 JSLint 中没有给出任何错误(除了“隐式全局:警报 2”)

结果

var t=true;if(t)alert("it's true!");

如果我使用“谁需要空白”设置来压缩它,这当然是优化的 ,但现在给出了 JSLint 错误。

I'm not sure what you are using to compress your javascript, but I have noticed from using the Google Closure compiler that it doesn't following the "rules" per se.

Given this code:

var t = true;
if (t) { alert("it's true!"); }

which gives no errors in JSLint (except for "Implied global: alert 2")

If I compress it using the "who needs whitespace" setting, this is the result

var t=true;if(t)alert("it's true!");

which is of course optimized, but now gives a JSLint error.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文