Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/469.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Internet Explorer 8中的Javascript substr_Javascript_Internet Explorer 8 - Fatal编程技术网

Internet Explorer 8中的Javascript substr

Internet Explorer 8中的Javascript substr,javascript,internet-explorer-8,Javascript,Internet Explorer 8,使用Internet Explorer 8运行以下代码时出错: for (var lang_elem in this.langElems) { if (this.langElems.hasOwnProperty(lang_elem)) { // ignore attributes down the prototype chain var www1 = this.langElems[lang_elem].length; var xxx1 = line.su

使用Internet Explorer 8运行以下代码时出错:

for (var lang_elem in this.langElems) {
    if (this.langElems.hasOwnProperty(lang_elem)) {  // ignore attributes down the prototype chain
        var www1 = this.langElems[lang_elem].length;
        var xxx1 = line.substr(0, www1);
        var yyy1 = this.langElems[lang_elem];

        if (xxx1 == yyy1) {
            elem_type = lang_elem;
            break;
        }
    }
}
调试器在定义xx1的行中停止(我显然是为了调试目的定义了这三个变量),并显示以下消息:

UNTERBRECHANG bei JScript Laufzeitfehler-这是一种不适用于本征分类法的目标。

也就是说

在JScript运行时中断错误-对象不支持该属性或方法。

我检查了,但就我所知,IE8应该支持substr方法。我用line.substr(0,2)调用它,它应该可以工作(没有负参数)


有人知道为什么会显示此错误吗?

您确定此时
是字符串吗?这通常是当变量为null或未定义时出现的消息。尝试粘贴
console.log(行)就在调用substr之前。在您的示例中,我也看不到它的定义,但您可能只是错误地将其删除了。

在您显示的任何代码中都没有定义。什么是
?在它前面做一个
console.log(行的类型)
。输出是什么?使用slice或!!strLong.split(strSubStr)[1];很抱歉提供了这么小的信息-它来自一个大项目,我试图复制重要的部分。不过你的想法是对的,菲利普。谢谢!问题如下:由于IE8没有为数组提供.indexOf(),所以我“手动”定义了它。现在,在使用for-in遍历数组时,也考虑了此函数。我添加了if(typeof line!=“string”)中断;现在它按预期工作。非常感谢你的帮助。