【问题标题】:When I include only the jQuery 1.4 Library, I get an exception, why?当我只包含 jQuery 1.4 库时,我得到一个异常,为什么?
【发布时间】:2011-01-24 05:38:07
【问题描述】:

我在只包含 jquery 1.3 或 1.4 的地方不断收到此错误。

"设置一个只有 getter 的属性"

以及 Firefox 错误控制台中的一长串警告。

发生了什么事?我找不到关于这个问题的任何信息=/

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
<head>
  <title>Demo</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <link rel="shortcut icon" href="images/favicon.ico">
    <link rel="stylesheet" href="css/common.css" type="text/css" /> 
    <link rel="stylesheet" href="css/modules.css" type="text/css" /> 
    <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script> 
</head>  

只是一些警告sn-ps:

Warning: reference to undefined property a[++e] 
Source File: /js/jquery-1.4.2.min.js 
Line: 30 
Warning: reference to undefined property a[0] 
Source File: /js/jquery-1.4.2.min.js 
Line: 30 
Warning: function oa does not always return a value 
Source File: /js/jquery-1.4.2.min.js Line: 18, Column: 165 
Source Code: th;n<r;n++){j=d[n];a.currentTarget=j.elem;a.data=j.handleObj.data;a.handleObj=j.handleObj;if(j.handleObj.origHandler.apply(j.elem,e)===false){b=false;break}}return b}}function pa(a,b){return"live."+(a&&a!=="*"?a+".":"")+b.replace(/\./g,"`").replace(/ /g,

【问题讨论】:

  • 请显示您正在使用的完整 HTML 头部部分。
  • amvx,你一定是在做一些不正常的事情——据我所知,没有其他人使用 1.4.2 仅仅通过加载库就会收到这些错误。你能在 jsbin.com 上重现它吗?
  • Firefox 控制台有哪些错误?
  • 发布了一些警告问题

标签: javascript jquery firefox include


【解决方案1】:

您在任何地方都有"use strict"; 声明吗?这会导致 ECMAScript5 浏览器对 JavaScript 的解析略有不同,并可能导致它作为错误返回。

您可以删除它来修复错误,但这意味着您不会从use strict 中受益。请注意,use strict 可以在它执行的任何范围内工作。因此,如果您想将 jQuery 加载为非严格的,但让其余代码严格,您可以这样做:

//load jQuery here

//create a scope
(function() {
     "use strict";
     // your code here
})();

【讨论】:

  • 呃....弗洛伊德的失误——我的意思是——出于兴趣,哪些浏览器支持 ES5 的“使用严格”的东西?
  • DOCTYPE 是严格的。所以我看不出使用严格的范围是如何工作的。
  • 这只是 JavaScript 的严格模式。严格的文档类型只与 HTML 标记有关。
  • 但这不会发生在我的代码中,它发生在 jQuery 库中。
  • “ECMAScript5 浏览器” - 什么浏览器?
【解决方案2】:

虽然这个问题已经回答了,但我觉得这是必要的。

OP 可能在 Firefox 的 about:config 中开启了严格的警告。

要更改此值,只需在 Firefox 中加载 about:config,然后向下滚动到 javascript.options.strict,然后将此值更改为 "false"

【讨论】:

  • 其实... javascript.options.strict;false -- 已经设置为 false
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-07-13
  • 2011-12-13
  • 2015-03-17
  • 2011-04-14
  • 1970-01-01
  • 2018-06-22
  • 2012-03-12
相关资源
最近更新 更多