javascript - ie8 respond.js 'undefined' 为空或不是对象

标签 javascript jquery internet-explorer dom internet-explorer-8

我正在使用 respond.js (该库的+1)我得到了对象的以下功能并出错:

translate = function (styles, href, media) {
    // here I got 'undefined' error in IE 8
    var qs = styles.match(/@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi),
        ql = qs && qs.length || 0;

    //try to get CSS path
    href = href.substring(0, href.lastIndexOf("/"));

    var repUrls = function (css) {
        return css.replace(/(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g, "$1" + href + "$2$3");
    },
    useMedia = !ql && media;

    //if path exists, tack on trailing slash
    if (href.length) {
        href += "/";
    }

    //if no internal queries exist, but media attr does, use that   
    //note: this currently lacks support for situations where a media attr is specified on a link AND
    //its associated stylesheet has internal CSS media queries.
    //In those cases, the media attribute will currently be ignored.
    if (useMedia) {
        ql = 1;
    }

    for (var i = 0; i < ql; i++) {
        var fullq, thisq, eachq, eql;

        //media attr
        if (useMedia) {
            fullq = media;
            rules.push(repUrls(styles));
        }
        //parse for styles
        else {
            fullq = qs[i].match(/@media *([^\{]+)\{([\S\s]+?)$/) && RegExp.$1;
            rules.push(RegExp.$2 && repUrls(RegExp.$2));
        }

        eachq = fullq.split(",");
        eql = eachq.length;

        for (var j = 0; j < eql; j++) {
            thisq = eachq[j];
            mediastyles.push({
                media: thisq.split("(")[0].match(/(only\s+)?([a-zA-Z]+)\s?/) && RegExp.$2 || "all",
                rules: rules.length - 1,
                hasquery: thisq.indexOf("(") > -1,
                minw: thisq.match(/\(\s*min\-width\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/) && parseFloat(RegExp.$1) + (RegExp.$2 || ""),
                maxw: thisq.match(/\(\s*max\-width\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/) && parseFloat(RegExp.$1) + (RegExp.$2 || "")
            });
        }
    }

    applyMedia();
},

还有其他解决方法吗?我试过不同的...

最佳答案

我在第 121 行 (Respond.js 1.3.0) 中遇到了类似的问题。一个空的样式表导致了这个问题,删除它解决了这个问题。

没有足够的信息可以判断您的情况是否完全相同,但您可以尝试看看是否有帮助。

关于javascript - ie8 respond.js 'undefined' 为空或不是对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18468050/

相关文章:

javascript - 通过 jQuery 捕获具有特定数据切换的所有对象

javascript - 如何在 Google 表单中添加动态字段?

javascript - 创建新时如何检索模型ID?

javascript - JQuery 将项目添加到我的 JSON

internet-explorer - IE错误:无法设置属性'innerHTML'的值:对象为null或未定义

CSS Google 字体 - 斜体在 IE 中变长

javascript - jQuery 导航在 IE7 中不工作

javascript - jQuery 插件命名空间函数

javascript - 使用空对象进行枚举

javascript - 光标不在一个空的可编辑 anchor 中居中,在 Firefox 上具有文本对齐中心