【发布时间】:2012-10-11 02:44:10
【问题描述】:
可能重复:
What is the difference between object keys with quotes and without quotes?
兴趣,什么是正确的方法,用引号写对象键?那是
var obj = {
"name": "Jhon"
}
或
var obj = {
name: "Jhon"
}
例如,从 php 代码中,echo json_encode(array("a"=>"aaa","b"=>"bbb")); 结果是具有带引号的键的对象。
但是例如看 jquery animate,在文档中是不带引号的键,(这也是 JS 对象格式,对吧?)
$("#someElement").animate({
marginLeft: "200px"
},
{
duration: 1000
});
那么,更正确的方法是什么?
【问题讨论】:
-
关于 JSON 与对象字面量的好读物:benalman.com/news/2010/03/theres-no-such-thing-as-a-json
标签: javascript jquery object