js代码疑问
<script type="text/jajvascript">
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>
在浏览器显示为何毫无反应?
[解决办法]
var book={};
[解决办法]
- HTML code
<script type="text/javascript"> //"text/javascript",多了个jvar 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>