programming/jsp

자바스크립트 class화 하기

labj 2012. 3. 21. 13:22

* test.js

 var act = {}; // act.calendar 패키지 정의
 
 // 현재 년,월,일,span id, text id, 보기(안보기)
 act.calendar = function(calDivId, spanId, textId) {  
  this.calDivId = calDivId; //달력영역
  this.spanId = spanId; //달력 보이는 부분
  this.textId = textId; //날짜 입력 될 text
 }
 
 act.calendar.prototype = {
  
  test: function() { // 자바스크립트 날짜 객체
  
   return this.calDivId+'-'+this.spanId+'-'+this.textId;
  },
   
  currentDay: function() { // 자바스크립트 날짜 객체
   var today = new Date();
   return today;
  }

 }

 

* index.jsp

<%@ page contentType="text/html; charset=euc-kr" %>

<html>
<script type="text/javascript" src="./js/prototype.js" />"></script>
<script type="text/javascript" src="./js/test.js" />"></script>
<script language="JavaScript">
 window.onload = function() {
  logout();
 }
 function logout(){ 
  var calendar = new act.calendar(1, 2, 3);
  var calendar1 = new act.calendar(11, 12, 13);  
  var calendar2 = new act.calendar(21, 22, 23);
  
  alert(calendar.test() + calendar1.test() + calendar2.test());
  
 }
</script>

<body>
 
</bodY>
</html>


'programming > jsp' 카테고리의 다른 글

서블릿 테스트  (0) 2012.03.21
prototype & scriptaculous 인 액션 3장 예제  (0) 2012.03.21
jsp로 xml문서 만들기  (0) 2012.03.21
Prototype - A$() 함수  (0) 2012.03.21
이미지보여주기 - lightbox  (0) 2012.03.21