zoukankan      html  css  js  c++  java
  • JavaScript创建对象

    JavaScript创建对象


    1、实现源码

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>JavaScript创建对象</title>
    <script type="text/javascript">
    	 /**
    	  * 创建Person对象
    	  */
    	function Person(name,sex,age,addr)
    	{
    		this.name = name;
    		this.sex = sex;
    		this.age = age;
    		this.date = obDate();
    		this.addr = addr;
    		this.findInfo = function(){
    			name = "姓名:" + name + "<br>";
    			sex = "性别:" + sex + "<br>";
    			age = "年龄:" + age + "<br>";
    			date = "生日:" + obDate() + "<br>";
    			addr = "地址:" + addr;
    			document.writeln(name,sex,age,date,addr);
    		};
    	}
    	
    	/**
    	 * 获取现在日期
    	 */
    	function obDate()
    	{
    		var date = new Date();
    		var year = date.getFullYear();
    		var month = date.getMonth() + 1;
    		var day = date.getDate();
    		var thisDate = year + "-" + (month<10?"0"+month:month) + "-" + (day<10?"0"+day:day);	
    		
    		return thisDate;
    	}
    	
    	You = new Person("You","男","23","湖北省武汉市");
    	You.findInfo();
    </script>
    </head>
    
    <body>
    </body>
    </html>
    

    2、实现结果

    姓名:You
    性别:男
    年龄:23
    生日:2016-04-29
    地址:湖北省武汉市 


  • 相关阅读:
    Rocket
    Rocket
    Rocket
    Rocket
    POJ 1849 树的直径 Two
    SGU 495 Kids and Prizes
    HDU 4336 概率DP 状压
    HDU 4089 && UVa 1498 Activation 带环的概率DP
    SGU 149 树形DP Computer Network
    暑假集训刷题记录
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13314201.html
Copyright © 2011-2022 走看看