블로그 이미지
초딩입맛제주아재
하고 싶은 것만 하며 살고 싶다

calendar

1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
2006. 11. 8. 15:57 Programing/HTML/JavaScript/CSS

selectbox 에 항목을 추가 삭제 할때 자동으로 정렬을 해주는 방법이다.
만들때는 생각을 안했는데 해 놓고 보니 MVC or MVP 패턴과 닮았다.
Smalltalk의 영향인가...

항목(item)에 대한 Model 객체(Array)가 있고

var keyword_list = new Array();

Model에 변화가 생기면 View를 바꾼다.

function refreshList(){
   var listObj = document.getElementById('list');

   clearList();
   keyword_list.sort();

   var arr_text = '';

   for(var i=0; i<keyword_list.length; i++){
       var newOpt = document.createElement('OPTION');
       newOpt.value = keyword_list[i];
       newOpt.text = keyword_list[i];

       arr_text += '[' + i + '] => ' + keyword_list[i] + '<br />';
       listObj.add(newOpt);
   }

   document.getElementById('arrayDesc').innerHTML = arr_text;
}

전체 소스를 보자....

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<script language="JavaScript">
<!--

var keyword_list = new Array();

function itemAdd(){
   var keywordObj = document.getElementById('keyword');

   if(keywordObj.value == ''){
       keywordObj.focus();
       return false;
   }

   keyword_list.push(keywordObj.value);
   keywordObj.value = '';
   keywordObj.focus();

   refreshList();
}

function refreshList(){
   var listObj = document.getElementById('list');

   clearList();
   keyword_list.sort();

   var arr_text = '';

   for(var i=0; i<keyword_list.length; i++){
       var newOpt = document.createElement('OPTION');
       newOpt.value = keyword_list[i];
       newOpt.text = keyword_list[i];

       arr_text += '[' + i + '] => ' + keyword_list[i] + '<br />';
       listObj.add(newOpt);
   }

   document.getElementById(arrayStat).innerHTML = arr_text;
}

function itemRemove(){
   var listObj = document.getElementById('list');

   if(listObj.selectedIndex < 0){
       return false;
   }

   keyword_list.splice(listObj.selectedIndex,1);
   refreshList();
}

function clearList(){
   var listObj = document.getElementById('list');

   while(listObj.length > 0){
       listObj.remove(0);
   }
}
//-->
</script>
</head>

<body>
<input type="text" id="keyword" value="" />&nbsp;
<input type="button" value="추가" onClick=" itemAdd();" />
<hr />

<div>
   <div style="width: width: 120px; padding: 0; float: left;">
       <select id="list" size="10" style="width: 100px;">
       </select><input type="button" value="삭제" onClick=" itemRemove();" />
   </div>
   <div id="arrayStat" style="border: solid 1px #D9D9D9; width: 120px;"></div>
</div>
</body>
</html>

* 오른쪽에 보이는 레이어(arrayStat)는 Model의 상태를 나타내는 역할을 한다.

아무래도 배열을 쓰고 Model이 바뀔때마다 View를 초기화 하고 다시 뿌려주니
많은 데이터를 처리할때는 속도가 걸림돌이 될 것 같다.

posted by 초딩입맛제주아재
2006. 10. 19. 02:16 Programing/HTML/JavaScript/CSS
'overflow'
Value:   visible | hidden | scroll | auto | inherit
Initial:   visible
Applies to:   non-replaced block-level elements, table cells, and inline-block elements
Inherited:   no
Percentages:   N/A
Media:   visual
Computed value:   as specified
visible
This value indicates that content is not clipped, i.e., it may be rendered outside the block box.
hidden
This value indicates that the content is clipped and that no scrolling user interface should be provided to view the content outside the clipping region.
scroll
This value indicates that the content is clipped and that if the user agent uses a scrolling mechanism that is visible on the screen (such as a scroll bar or a panner), that mechanism should be displayed for a box whether or not any of its content is clipped. This avoids any problem with scrollbars appearing and disappearing in a dynamic environment. When this value is specified and the target medium is 'print', overflowing content may be printed.
auto
The behavior of the 'auto' value is user agent-dependent, but should cause a scrolling mechanism to be provided for overflowing boxes.

example:

<div style="width: 300px; height: 200px; overflow: hidden;">
   contents
</div>

-> contents의 길이가 지정된 영역을 벗어나면 보이지 않는다.

<div style="width: 300px; height: 200px; overflow: scorll;">
   contents
</div>

-> contents의 길이에 상관 없이 스크롤바가 생성된다.

<div style="width: 300px; height: 200px; overflow: auto;">
   contents
</div>

-> contents의 길이에 따라 스크롤바가 생성되거나 사라진다.

<div style="width: 300px; height: 200px; overflow: visible;">
   contents
</div>

-> 레이어의 크기가 contents에 맞추어 확장된다.


overflow 속성은 고정된 영역에서 레이아웃을 해치지 않고
컨텐츠를 보여주고자 할떄 유용하게 쓰일 수 있다.
posted by 초딩입맛제주아재
2006. 10. 9. 11:08 Programing/HTML/JavaScript/CSS
if(object.addEventListener) {
   object.addEventListener('change',event_listener,false);
}else{
   object.attachEvent('onchange',event_listener);
}

function event_listener(){
   alert('object 의 change 이벤트에 반응하는 리스너');
}

- 이벤트 리스너 추가 메서드
   IE        : attachEvent(event.type,listener)
   Mozila : addEventListener(event.type,listener,useCapture)
   * Mozila 의 event.type 은 IE의 그것과는 달리 접두사 'on'이 붙지 않는다는점에 유의.


- 이벤트 리스너 삭제 메서드
   IE        : object.detachEvent(event.type,listener)
  Mozila : removeEventListener(event.type,listener,useCapture)

posted by 초딩입맛제주아재
2006. 7. 18. 14:08 Programing/HTML/JavaScript/CSS

xmlhttprequest 객체를 사용하면 참 편리하다.
이른바 AJAX의 핵심이 바로 이 객체가 아닌가 한다.

xmlhttprequest 객체를 사용하여 데이터를 PHP파일로 송신하면
데이터는 utf-8로 인코딩되어 전송된다.

var url = some url;
var param = 'id=myid&password=mypass&name=유시형';


xmlHttpPost(url,param,result function);

위 처럼 인자값에 한글이 들어갈 경우에는
제대로 전송이 되지 않는다.

var param = 'id=myid&password=mypass&name=' + escape(encodeURIComponent('이름'));

encodeURIComponent,escape 두 함수를 이용해서 가공을 한번 해줘야 제대로 전달이 된다.


다음으로 PHP에서 위 인자값을 받을때는

$id = $_POST['myid'];
$pass = $_POST['password'];
$name = iconv('UTF-8','EUC-KR',urldecode($_POST['name']));

자바스크립트에서 함수를 적용한 역순으로 decoding을 먼저 해주고
문자셋을 euc-kr로 변경해주면 된다.

물론,
서버셋팅이 UTF-8로 되어 있다면 위처럼 귀찮은 짓은 하지 않아도 된다.
역시 대세는 UTF-8이다....


posted by 초딩입맛제주아재
2006. 7. 3. 13:27 Programing/HTML/JavaScript/CSS

브라우저 내장객체 - navigator 객체

navigator.appName - 웹이름
navigator.appVersion - 웹버전
appCodeName - 브라우저의 코드명 반환
appVersion - 현재 사용중인 브라우저 버전 반환
appName - 현재 사용중인 브라우저 이름 반환
mimeType - MIME 형식의 정보 반환
plugins - 플러그인 정보 반환
platform - 사용중인 시스템 코드 반환
userAgent - 브라우저의 이름, 버전, 코드 포함하는 문자열 반환

posted by 초딩입맛제주아재
2006. 5. 11. 01:01 Programing/HTML/JavaScript/CSS

아래 내용은 피넷의 qna 게시판에 '엔젠드'님이 올린 질문에 대한
답변들을 인용한 것이다.

DIV의 height값은 default로 font-size를 갖는 듯(?) 하다...
<div style="height: 2px; border: solid 1px #000000;"></div>
<div style="background-color: #D9D9D9;">가운데...</div>
<div style="height: 2px; border: solid 1px #000000;"></div>

위 소스를 브라우져에서 보면
위 아래를 감싸고 있는 레이어의 height는 2px보다 크다.
하지만 font-size속성을 2px로 잡아 주면 height값이 2px로 된다...

추가로 '낭망백수'님의 답으로
overflow값을 이용한 방법도 있었다.
hidden 값을 설정한...

이건 아직 테스트를 못했다.
내일 해보고....

posted by 초딩입맛제주아재
prev 1 2 3 4 next