JavaScript的跨浏览器:它是安全的治疗字符串数组? [英] JavaScript cross-browser: Is it safe to treat a string as array?
本文介绍了JavaScript的跨浏览器:它是安全的治疗字符串数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在所有主要的浏览器这个code安全吗?
VAR字符串='123'
警报(字符串[1] =='2')//应警惕真
解决方案
没有,这不是安全的。 Internet Explorer 7中不支持索引访问字符串。
您必须使用的charAt
方法是用compatibale IE7:
VAR字符串='123';
警报(string.charAt(1)=='2');
Is this code safe in all major browsers?
var string = '123'
alert(string[1] == '2') // should alert true
解决方案
No, it's not safe. Internet Explorer 7 doesn't support accessing strings by index.
You have to use the charAt
method to be compatibale with IE7:
var string = '123';
alert(string.charAt(1) == '2');
这篇关于JavaScript的跨浏览器:它是安全的治疗字符串数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文