Develop
2013.04.23 15:10
[js] 셀렉트박스(select)의 옵션(option) 동적으로 추가/제거
Views 8060 Comment 0
Attachment '1' |
---|
좋은 예제인듯..
아래는 주요 함수 부분임~
<script> /* *Source Select의 요소(option)를 Target Select로 복사한다. */ function copyElement(sourceObj, targetObj){ var elms = sourceObj.options; for( i = 0, k = elms.length; i < k; i++ ){ if( elms[i].selected ){ targetObj.add(new Option(elms[i].text, elms[i].value, false, false)); } } sourceObj.selectedIndex=-1; } /* *Source Select의 요소(option)를 제거한다. */ function removeElement(sourceObj){ var elms = sourceObj.options; var posArr = new Array(); var increase = 0; for( i = 0, k = elms.length; i < k; i++ ){ if( elms[i].selected ){ posArr[increase++] = elms[i].value; } } for( i = 0, k = posArr.length; i < k; i++ ){ for( x = 0, y = elms.length; x < y; x++ ){ if( (posArr[i] == elms[x].value) && elms[x].selected ){ sourceObj.remove(x); x = 0; y--; } } } } /* *Source Select의 요소(option)를 Target Select로 이동한다. */ function moveElement(sourceObj, targetObj, isSort){ var elms = sourceObj.options; for( i = 0, k = elms.length; i < k; i++ ){ if( elms[i].selected ){ targetObj.add(new Option(elms[i].text, elms[i].value, false, false)); } } removeElement(sourceObj); sourceObj.selectedIndex = -1; } /* *Source Select의 요소(option)의 상하순서를 바꾼다. */ function move_option_in(src,to) { if(!src)return; var src_index = src.selectedIndex; if(src_index<0)return; if(to == "up"){ if(src_index==-1||src_index==0)return; var tempoption = new Option(src.options[src_index].text, src.options[src_index].value); src.options[src_index] = new Option(src.options[src_index-1].text, src.options[src_index-1].value); src.options[src_index-1]=tempoption; src.options[src_index-1].selected=true; }else if(to == "down"){ if(src_index>=src.options.length-1)return; var tempoption = new Option(src.options[src_index].text, src.options[src_index].value); src.options[src_index] = new Option(src.options[src_index+1].text, src.options[src_index+1].value); src.options[src_index+1]=tempoption; src.options[src_index+1].selected=true; } } </script>
No. | Category | Subject | Author | Date | Views |
---|---|---|---|---|---|
313 | Develop | [ios] Objective-C에서 형식이 있는 문자열(Format Strings)에 사용할 수 있는 토큰들(Tokens) | hooni | 2013.04.23 | 18783 |
312 | Develop | [ios] Objective-C 특정 문자 찾아 제거하기 | hooni | 2013.04.23 | 28065 |
311 | Develop | [ios] Objective-C 문자열 잘라서 배열(NSArray)에 넣기 | hooni | 2013.04.23 | 29415 |
310 | Develop | [Xcode] 디버깅 옵션 | hooni | 2013.04.23 | 57196 |
309 | Develop | 웹페이지 성능 테스트 툴 설명 | hooni | 2013.04.23 | 27445 |
308 | Develop | [ios] 개발 기초 가이드 링크.. | hooni | 2013.04.23 | 31366 |
307 | Develop | 논문 실험용 고려대 툴바 ㅎㅎ | hooni | 2013.04.23 | 8686 |
306 | Develop | [ios] NSMutableString 문자열 패턴 교환 | hooni | 2013.04.23 | 28991 |
305 | Develop | [iphone] view에 대한 조사 ㅡ,.ㅡ; | hooni | 2013.04.23 | 54071 |
304 | Develop | [ios] 구분자로 문자열 자르기 (split) | hooni | 2013.04.23 | 26271 |
303 | Develop | [ios] 아이폰 개발 총정리.. | hooni | 2013.04.23 | 23863 |
302 | Develop | [ios] Debug Extensions (from 종길 차장님 ㅋㅋ) | hooni | 2013.04.23 | 17693 |