日期:2014-05-16 浏览次数:20336 次
<script type="text/javascript"> //"text/javascript",多了个j var book = {}; //创建对象直接量,少了个 = book.title="hello word"; book.chapter1 = new Object(); //创建新对象,Object(),大小写敏感 book.chapter1.title="hehe"; book.chapter1.pages=6; book.chapter2={title:"qq",pages:6}; alert("title"+book.title+"\n\t"+"cp1"+book.chapter1.title+"\n\t"+"cp2"+book.chapter2.title); </script>
------解决方案--------------------
正确写法:
<script type="text/javascript">
alert("测试开始!");
var book={};
book.title="hello word";
book.chapter1=new Object();
book.chapter1.title="hehe";
book.chapter1.pages=6;
book.chapter2={title:"qq",pages:6};
alert("title"+book.title+"\n\t"+"cp1"+book.chapter1.title+"\n\t"+"cp2"+book.chapter2.title);
</script>