gpt4 book ai didi

JavaScript 错误 : "null or not an object"

转载 作者:行者123 更新时间:2023-11-30 05:53:49 25 4
gpt4 key购买 nike

我这里有个奇怪的问题: http://jackyon.com.s146246.gridserver.com/thehappymonk/

我正在使用 queryloader2 插件和 maximage2 插件。它在所有现代浏览器上运行良好,但在 IE8 或更低版本上显示 javascript 错误。即使IE9显示错误,也能正常运行。

js error: 'a.Slide[...].content.length' is null or not an object.

删除任一插件时,页面运行没有错误。

万分感谢你们!这个问题已经让我发疯了几天。请帮我!谢谢!!

最佳答案

错误似乎来自 jquery.maximage.min.js,完整版本在这里:https://github.com/akv2/MaxImage/blob/master/lib/js/jquery.maximage.js

寻找什么的一个线索是有一个“use strict”指令,这对于打算在不支持严格模式的浏览器中运行的代码来说不是一个好主意。似乎没有任何充分的理由使用它。我想这只是时髦。

有一些基于 UA 字符串的浏览器嗅探(不是一个好兆头):

if($.browser.msie){
// Stop IE from continually trying to preload images that we already removed
document.execCommand("Stop", false);
}

无论如何,错误似乎与第 226 行周围的代码有关:

for(var j in $.Slides) {

// Determine content (if container or image)
if($.Slides[j].content.length == 0){
c = '<img src="' + $.Slides[j].url + '" />';

} else {
c = $.Slides[j].content;
}
...
}

所以找哪里Slides[j].content被赋值,在第625行有:

  $.Slides = Utils.construct_slide_object();

construct_slide_object是:

construct_slide_object: function() {
var obj = new Object(),
arr = new Array(),
temp = '';

$self.children().each(function(i) {
var $img = $(this).is('img') ? $(this).clone() : $(this).find('img').first().clone();

这只是一个很长的写作方式吗$('<img />')

    // reset obj
obj = {};

那么为什么要将它初始化为 each 之外的对象呢?功能?

    // set attributes to obj
obj.url = $img.attr('src');
obj.title = $img.attr('title') != undefined ? $img.attr('title') : '';

这只是一个很长的写法:

    obj.title = $img.attr('title');

attr将始终返回一个字符串,并且 $img.attr('title') != undefined仅当它返回空字符串时才为真。

    obj.alt = $img.attr('alt') != undefined ? $img.attr('alt') : '';
obj.theclass = $img.attr('class') != undefined ? $img.attr('class') : '';
obj.styles = $img.attr('style') != undefined ? $img.attr('style') : '';
obj.orig = $img.clone();
obj.datahref = $img.attr('data-href') != undefined ? $img.attr('data-href') : '';
obj.content = "";

// Setup content for within container
if ($(this).find('img').length > 0) {

这是这段短代码中第三次使用它。

      if($.BrowserTests.cssBackgroundSize) {
$(this).find('img').first().remove();

还有第四个,$(this)使用了 7 次。

      }
obj.content = $(this).html();
}

// Stop loading image so we can load them sequentiallyelse{
$img[0].src = "";

// Remove original object (only on nonIE. IE hangs if you remove an image during load)
if ($.BrowserTests.cssBackgroundSize) {

这似乎是某种浏览器推断:如果 backgrounsize 测试返回 false,则一定是 IE。

        $(this).remove();
}

// attach obj to arr
arr.push(obj);
});

if(config.debug) {
debug(' - Slide Object - ');
debug(arr);
}
return arr;
},

穿上你的 Boot 。 :-)

关于JavaScript 错误 : "null or not an object",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13151171/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com