본문 바로가기
my_lesson/_JQuery

JavaScript [Date, Print]객체를 생성하고 메서드를 생성해보자

by boolean 2015. 4. 11.
728x90
index

JavaScript [Date, Print]객체를 생성하고 메서드를 생성해보자


How to use Date


테스트는 링크된 원문이나 팝업창에서 해보자


    

  	<script type="text/javascript">
  		function Student(name, dept, grade)
  		{
  			this.name  = name;
  			this.dept  = dept;
  			this.grade = grade;

  			this.print = print;
  		}

  		function print()
  		{
  			document.write(this.name+ "님은"+ this.dept+ "과"+ this.grade+ 
                                               "학년 학생입니다.<br />")
  		}
  	</script>

  	<script type="text/javascript">
  		s1    = new Student("Jhon", "Computer Sience", 2);
  		s2    = new Student("Jane", "History", 2);
  		cDate = new Date();

  		document.write("("+ cDate.getYear()+ "년"+ (cDate.getMonth()+1)+
                                      "월"+ cDate.getDate()+ "일 현재)<br />");
  		document.write(s1.name+ "님은"+ s1.dept+ "과"+ s1.grade+ "학년 학생입니다.<br />");
  		document.write(s2.name+ "님은"+ s2.dept+ "과"+ s2.grade+ "학년 학생입니다.<br />");
  		s1.print();
  		s2.print();
  	</script>
  

원문보기:Date, Print

댓글