开发者

Javascript Json problem in IE9

开发者 https://www.devze.com 2023-04-06 23:42 出处:网络
Hy guys. In firefox and chrome this script alerts \'myclass\', but does nothing in IE (i have version 9).

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

精彩评论

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