在項目中需要實現如下的效果內容。如圖:
具體實現的源碼如下:
兩個框的頁面源碼:
已選角色: > class=btn1 onclick=moveOptions(document.getElementById('roleIds'),document.getElementById('roleList')); /> 備選角色:
function moveOptions(oSource, oTarget) { while (oSource.selectedIndex > -1) { var opt = oSource.options[oSource.selectedIndex]; oSource.removeChild(opt); var mark = true; for(var i = 0; i < oTarget.options.length; i++){ if(opt.value == oTarget.options[i].value){ mark = false; } } if(mark){ var newOpt = document.createElement(OPTION); oTarget.appendChild(newOpt); newOpt.value = opt.value; newOpt.text = opt.text; newOpt.selected = true; } } }