ie8 respond.js'undefined'是null或不是一个对象 [英] ie8 respond.js 'undefined' is null or not an object

查看:157
本文介绍了ie8 respond.js'undefined'是null或不是一个对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 respond.js (该库为+1),而我正在获得以下功能的错误的对象:

I'm using respond.js (+1 for that library) and I'm getting and error to the following function of the object:

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();
},

有没有其他解决方法?我尝试过不同的...

Are there any other workarounds? I have tried different ones...

推荐答案

我在第121行(Respond.js 1.3.0)中有一个类似的问题,一个空的样式表导致了问题并将其解除了oblem。

I had a similar issue in line 121 (Respond.js 1.3.0). An empty stylesheet was causing the issue and removing it solved the problem.

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

There is not enough information to tell if your case is exactly the same, but you may try and see if it helps.

这篇关于ie8 respond.js'undefined'是null或不是一个对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆