b

DOM 이용 select box 옵션추가삭제

· 18년 전 · 3729

<style>
#list {width:140; height:100px;}
</style>

<script type="text/javascript">
<!--
    var header = {
        input : '',
        sel : '',
        
        init: function()
        {
            this.input = document.getElementById('input_head');
            this.sel = document.getElementById('list');
            var addbtn = document.getElementById('addbtn');
            var delbtn = document.getElementById('delbtn');
            addbtn.onclick = function() {header.addHeader();}
            delbtn.onclick = function() { header.delHeader(); }
            
        },
        addHeader: function()
        {
            var newOpt = document.createElement('option');
            newOpt.text = this.input.value;
            newOpt.value = this.input.value;
            this.sel.add(newOpt);
            this.input.value= '';
        },
        
        delHeader: function()
        {
            this.sel.remove(this.sel.selectedIndex);
        }
    };
//-->
</script>
<div><input type="text" size="20" id="input_head"><button id="addbtn">추가</button></div>
<div><select id="list" size="10"></select></div><button id="delbtn">삭제</button>
<script type="text/javascript">    header.init();</script>
[이 게시물은 관리자님에 의해 2011-10-31 16:57:14 JavaScript에서 이동 됨]
|
댓글을 작성하시려면 로그인이 필요합니다. 로그인

팁게시판

디자인과 관련된 유용한 정보를 공유하세요. 질문은 상단의 QA에서 해주시기 바랍니다.

+
제목 글쓴이 날짜 조회
18년 전 조회 3,305
18년 전 조회 3,127
18년 전 조회 3,843
18년 전 조회 2,158
18년 전 조회 2,333
18년 전 조회 9,992
18년 전 조회 3,494
18년 전 조회 3,291
18년 전 조회 3,169
18년 전 조회 2,786
18년 전 조회 4,136
18년 전 조회 5,482
18년 전 조회 3,730
18년 전 조회 3,180
18년 전 조회 3,593
18년 전 조회 2,253
18년 전 조회 2,686
18년 전 조회 3,916
18년 전 조회 2,840
18년 전 조회 4,352
18년 전 조회 2,067
18년 전 조회 2,509
18년 전 조회 2,400
18년 전 조회 3,753
18년 전 조회 3,812
🐛 버그신고