IE8错误:为null或不是对象,但仍然可以跟踪/控制台注销
IE8 Error: is null or not an object, but can still trace/console log out
我在IE8中遇到了一个JS错误,但就我而言,似乎找不到这个错误引发的原因。
我引用的是一个JSON文件,该文件已被jQuery的$.getJSON()
请求并解析。完成后,我将使用一个触发的事件(pub/sub),并从那里对解析后的JSON文件执行所需的操作。
直到,IE8在imgPath
变量声明上抛出一个错误(如下)。我正在通过src
属性将图像加载到<img>
标签中。
//This is function is inside a object
IE8_loadImage: function($root, data) {
var self = this,
$comp = $root.data('comp').parent,
$imgHolder = $root.data('comp').IE8holder,
imgPath = $root.data('json')[data.scene][data.convo]['ie8Img'];
console.log(typeof $root.data('json')); //outputs to 'object'
console.log(imgPath); //outputs to 'images/1-0.jpg'
console.log(typeof imgPath); //output 'string'
console.log(typeof data.scene); //output 'string'
console.log(typeof data.convo); //output 'string'
//Set the source
$imgHolder.css('z-index', 5).attr('src', imgPath);
},
奇怪的是,我可以console.log出imgPath
变量,并从JSON中获得预期的结果。
JSON(在jsonlint.com上检查)文件如下:
{
"demo": {
"scene1": {
"c0": {
"text": "Lorem ipsum Tempor magna nisi non enim fugiat do dolor dolore esse aliquip irure ullamco cillum dolor reprehenderit eiusmod dolore irure commodo et reprehenderit voluptate dolore Ut in Duis tempor tempor esse et Duis enim.",
"ie8Img": "images/1-0.jpg",
"audio": {
"source": "audio/s1-1.mp3",
"autoplay": "true"
}
},
"c1": {
"text": "Lorem ipsum Tempor magna nisi non enim fugiat do dolor dolore esse aliquip irure ullamco cillum dolor reprehenderit eiusmod dolore irure commodo et reprehenderit voluptate dolore Ut in Duis tempor tempor esse et Duis enim.",
"ie8Img": "images/1-1.jpg",
"audio": {
"source": "",
"autoplay": "false"
}
}
}
}
任何想法,或者仅仅是对为什么会发生这种情况的第二双眼睛,都将是很棒的!谢谢
编辑:错误消息为data(...)[...][...].ie8Img is null or not an object
似乎是我用scrollTop动画触发了双重回调的问题:
$('html,body').animate({
scrollTop: $elem.offset().top - offset
}, self.options.speed, function() {
// Callback function here...
callback();
});
因此,通过调试器跟踪我的代码,该事件在IE8中为"html"answers"body"触发了两次。因此,我最终使用.promise()
在动画完成后只触发一次回调。由于它发射了两次,变量更新得太快了。
相关文章:
- 动态分配GA增强型电子商务跟踪器
- 跟踪在页面加载时应用内联样式的JavaScript
- 跟踪用户点击Adsense广告的IP地址
- 跟踪jqplot垂直折线图的鼠标位置
- 点击facebook像素跟踪注册(JS/JQUERY代码)
- 显示具有服务器端自动时间注销的同步倒计时计时器
- 有没有一种方法可以从URL跟踪请求的域
- Javascript-在视频中跟踪鼠标位置
- 我们如何在互联网断开连接或用户关闭选项卡/浏览器时调用注销servlet
- 在Google Analytics中跟踪用户,但只能在两个操作之间跟踪
- 如何使用Google Analytics跟踪表单提交
- Fresh Spark Install+Homestead上的Vue异步堆栈跟踪错误
- 如何使用angular _ design保持全局当前用户直到注销
- 为什么是FB.注销用户功能不会重定向到我告诉它的 URL
- 代码挑战:创建一个跟踪对象实例总数的类Foo
- 打印javascript控制台的堆栈跟踪
- 谷歌分析:如何跟踪移动网站的点击量作为对主网站的点击
- 即使光标位于屏幕边缘,也可以跟踪鼠标速度
- IE8错误:为null或不是对象,但仍然可以跟踪/控制台注销
- 如何在php中的数据库表中跟踪注销的用户