具體實現的源碼如下:
兩個框的頁面源碼:
已選角色:<br /> <select multiple="multiple" name="roleIds" size="10" id="roleIds"> <option value="1"> 主任 </option> <option value="2"> 醫師 </option><option value="3"> 護士 </option><option value="4"> 前臺 </option><o
實現的js代碼:
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; } } }
新聞熱點
疑難解答