저자 마 지아난 새 문서 Java JavaScript C HTML CSS .Net [Ctrl A 모두 선택 참고: 외부 J를 도입해야 하는 경우 실행하려면 새로 고쳐야 합니다 ] var currentSel = null; function move(){ if(arguments.length==1){ moveUp(arguments[0]); }else if(arguments.length==2){ moveRight(arguments[0],arguments[1]); } } function moveUp(direction){ if(currentSel == null) return; var index = currentSel.selectedIndex; if(direction){//up if(index==0) return; var value = currentSel.options[index-1].value; var text = currentSel.options[index-1].text; currentSel.options[index-1].value = currentSel.options[index].value; currentSel.options[index-1].text = currentSel.options[index].text; currentSel.options[index].value = value; currentSel.options[index].text = text; currentSel.options[index].selected = false; currentSel.options[index-1].selected = true; }else{//down if(index==(currentSel.length-1)) return; var value = currentSel.options[index+1].value; var text = currentSel.options[index+1].text; currentSel.options[index+1].value = currentSel.options[index].value; currentSel.options[index+1].text = currentSel.options[index].text; currentSel.options[index].value = value; currentSel.options[index].text = text; currentSel.options[index].selected = false; currentSel.options[index+1].selected = true; } } function moveRight(src,des){ if(src.selectedIndex==-1){ alert("Please select first!"); return; } for(var i=0;i<src.length;i++){ if(src[i].selected){ var op = document.createElement("option"); op.value = src.options[src.selectedIndex].value; op.text = src.options[src.selectedIndex].text; des.options.add(op); src.remove(i); i--; } } } function setButton(obj){ if(obj.length==0) return; currentSel = obj; if(obj.id=="leftSel"){ document.getElementById("btnLeft").disabled = true; document.getElementById("btnRight").disabled = false; reSelect(document.getElementById("rightSel")); }else{ document.getElementById("btnLeft").disabled = false; document.getElementById("btnRight").disabled = true; reSelect(document.getElementById("leftSel")); } } function reSelect(obj){ for(var i=0; i<obj.length; i++){ if(obj[i].selected) obj[i].selected = false; } }