当前位置:编程学习 > JS >>

关于javascript中for……in语句的疑问

<html>
<head><title>无标题文档</title></head>
<body>
<script language="javascript">
<!--
function Student()
{
this.name="张华";
this.age="19";
this.height="172";
}
var attr=new Student;
var prop,stru=" ";
for(prop in attr)
{
stru+=prop+" ";
}
alert(stru);

//-->
</script>
</body>
</html>
该程序中prop虽然已经定义过但并为对其赋值,它在程序中到底是干什么的?
追问:兄弟,这该我好好教教你了。可以放在<head></head>间也可以放在<body></body>间!!
答案:<html>
<head><title>无标题文档</title></head>
<body>
<script language="javascript">
<!--
function Student()
{
this.name="张华";
this.age="19";
this.height="172";
}
var attr=new Student;
var prop,stru=" ";
for(prop in attr)
{
stru+=attr[prop]+" ";
}
alert(stru);

//-->
</script>
</body>
</html>

倒塌!!!

script 是放在 <head></head>标签内的!~

你怎么放在<body></body>内了?!!

上一个:javascript:void(0)怎么能让它消失
下一个:谁能帮我把javascript中的表达式、运算符、还有语句总结下,谢谢

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,