Javascript:定义属性值并输出(及with方法

<html>
<head>
</head>
<body>
<script language=javascript>
var books=new Object();{
books.code="123122";
books.title="西游记";
books.author="吴承恩";
books.price="30";
document.write("书号:"+books.code+"<br>");
document.write("书名:"+books.title+"<br>");
document.write("作者:"+books.author+"<br>");
document.write("价格:"+books.price+"<br>");
}
</script>
</body>
</html>
with方法
<html>
<head>
</head>
<body>
<script language=javascript>
var books=new Object();
with(books){
code="123122";
title="西游记";
author="吴承恩";
price="30";
document.write("书号:"+code+"<br>");
document.write("书名:"+title+"<br>");
document.write("作者:"+author+"<br>");
document.write("价格:"+price+"<br>");
}
</script>
</body>
</html>
for方法
<html>
<head>
</head>
<body>
<script language=javascript>
var objectes={书号:"123122",名称:"西游记",作者:"吴承恩",价格:"30"};
for(var prop in objectes){
document.write(prop+"="+objectes[prop]+"<br>")
}
</script>
</body>
</html>
Tags: 

延伸阅读

最新评论

发表评论