Javascript 和 Internet Explorer 8 错误

Javascript and Internet explorer 8 error

我有以下几行Javascript:

function SetTabIndex() {
    var test = document.getElementsByTagName("input");

    for (var i = 0; i < test.length; i++) {

        var cssText = test[i].getAttribute('style'),
            tabindex = cssText.match(/tabindex\s*:\s*(\d+)/);

        if (tabindex) {
            test[i].setAttribute('tabindex', tabindex[1]);
        }
    }
}

当我在本地 运行 执行此操作时,脚本 运行 会执行我想要的操作。但是,当我把它放在我的目标系统(只有 IE8 并且不能更新)上时,代码没有 运行。

我检查了我的日志,我收到以下错误:

Object doesn't support this property or method

当我点击它旁边的 link 时,它会将我带到以下代码行:

tabindex = cssText.match(/tabindex\s*:\s*(\d+)/);

我已经尝试取出我的一些正则表达式代码,但它仍然会抛出一个错误。当我拿走那条线并输入一些控制台输出时,一切正常。

是否有特殊原因说明为什么这在 IE8 上不起作用,即使我在更新版本的 IE 上对其进行了本地测试,并将其设置为可以很好地模拟 IE8?

Internet explorer 8 JScript regular expression bug中给出了以下答案:

The issue here was that "\s" in javascript does not include a non breaking space in IE but includes a non breaking space in FF.