当前位置: 动力学知识库 > 问答 > 编程问答 >

html - Javascript and Internet explorer 8 error

问题描述:

I have the following lines of 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]);

}

}

}

When I run this locally, the script runs and does exactly what I want it to. But, when I put this on my target system (which only has IE8 and can't be updated) the code doesn't run.

I've checked my log and I get the following error:

Object doesn't support this property or method

When I click the link next to it, it takes me to the following line of code:

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

I've tried taking out some of my regex code, but it still throws up an error. When I take that line away and throw in some console outputs, everything works fine.

Is there a particular reason as to why this doesn't work on IE8 even though I tested it locally on my more updated version of IE with it set to emulate IE8 just fine?

网友答案:

In Internet explorer 8 JScript regular expression bug the following answer was given:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: