为什么这个javascript字符串代码不能在Internet Explorer 7中运行?

时间:2021-03-17 21:05:08

I have the following code that works fine in IE8, firefox, chrome but not in IE7

我有以下代码在IE8,Firefox,Chrome中工作正常但在IE7中没有

Can someone please explain why this code below doesn't work in IE7 ?

有人可以解释为什么下面的代码在IE7中不起作用?

  var myString = $(this).attr("id");
  var nextStep = myString [myString.length - 1];

basically, IE7 doesn't seem to understand this line:

基本上,IE7似乎并不理解这一行:

   myString [myString.length - 1]

In this case myString is just a regular string that i am parsing out from the id of a div.

在这种情况下,myString只是一个常规字符串,我从div的id解析出来。

1 个解决方案

#1


4  

IE7 does not recognize indexing a string in that way. You need to use myString.charAt(myString.length - 1).

IE7无法识别以这种方式索引字符串。您需要使用myString.charAt(myString.length - 1)。

Array-like indexing of a string was added to ECMAScript 5, which was released well after IE7 was. More info

类似于数组的字符串索引被添加到ECMAScript 5,它在IE7之后很好地发布了。更多信息

#1


4  

IE7 does not recognize indexing a string in that way. You need to use myString.charAt(myString.length - 1).

IE7无法识别以这种方式索引字符串。您需要使用myString.charAt(myString.length - 1)。

Array-like indexing of a string was added to ECMAScript 5, which was released well after IE7 was. More info

类似于数组的字符串索引被添加到ECMAScript 5,它在IE7之后很好地发布了。更多信息