IE7 Javascript和使用字符串数组 [英] IE7 Javascript and using string as an array

查看:528
本文介绍了IE7 Javascript和使用字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

怪异的行为,我只是张贴了这个问题,看看是否有人知道这还是我的code是完全错误的原因:

Weird behavior and I'm just posting this question to see if anyone knows the reason for this or whether my code is just plain wrong:

string text = "~"; //yip, let's take some weird character
alert(text[0]);
//all major browsers output "~"
//IE6 & 7: undefined
alert(text.charAt(0));
//works in all browsers

现在我的问题是:使用文本在IE7不支持的阵列,是code错一般是OK使用 .charAt(我)而不是字符串[我]

Now my question is: Is using a text as an array not supported in IE7, is the code wrong in general and is it OK to use .charAt(i) instead of string[i]?

PS:有<一个href=\"http://stackoverflow.com/questions/2526019/simple-javascript-string-problem-in-ie6-and-ie7\">some那个谁回答了有关正是这种了自己的问题。我的问题是:究竟是怎么记录?这是一个普通的IE虫?

PS: There is some guy who answered his own question regarding exactly this. My question remains: Where is this documented? Is this a regular IE "bug"?

推荐答案

访问字符串数组一样不标准在ECMAScript中3:

Accessing string array-like is not standard in ECMAScript 3:

<一个href=\"https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String#section_5\">https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String#section_5

阵列状字符访问(上面的第二个方法)是不的一部分
  ECMAScript的3这是一个JavaScript和ECMAScript 5功能。

Array-like character access (the second way above) is not part of ECMAScript 3. It is a JavaScript and ECMAScript 5 feature.

你做什么是分割字符串:

What you do is split the string:

var textChars = text.split('');
alert(textChars[0]);

这篇关于IE7 Javascript和使用字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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