开发者

Javascript Json problem in IE9

Hy guys. In firefox and chrome this script alerts 'myclass', but does nothing in IE (i have version 9).

var a = {"class" : "myclass"};   
alert(a.class);

if I use cssclass instead of class, it is working in IE too.

var a = {"cssclass" : "myclass"};   
alert(a.cssclass);

This is very annoying. I开发者_如何学Gos the word 'class' reserved in IE, or what can be the problem, and what is the solution?


I think class is a reserved keyword. Because objects are associative arrays in javascript you could also use this to access the value:

alert(a['class']);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜