码迷,mamicode.com
首页 > 编程语言 > 详细

JavaScript - 对象专用语句[ for...in 语句 ]

时间:2014-09-21 22:31:41      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:javascript   王吉平   

<html>

	<head>
		
	<head>

	<body>
		<script language="javascript">
		// 对象专用语句
		// for...in语句
		/*
		 *	for(变量 in 对象){
		 *		执行语句块
		 *	}
		 */
			function Person(){
				this.name = "wjp" ;
				this.age = 22 ;
				this.height = 178 ;
			}
			
			var p1 = new Person() ;
			var prop, str = "" ;
			// 取出对象中所有的对象名
			for(prop in p1){
				str += prop + " ";
			}
			// 取出对象所有值
			for(prop in p1){
				str += p1[prop] + " ";
			}
			
			alert(str);
		</script>
	</body>

</html>

JavaScript - 对象专用语句[ for...in 语句 ]

标签:javascript   王吉平   

原文地址:http://blog.csdn.net/imwangjiping/article/details/39455713

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!