本帖最后由 qq914260102 于 2013-10-14 16:02:07 编辑 如果选到右边,是无法获取到值的,必须要点击一次,选中了才能获取到,怎么让右边的默认能获取值
sortitems = 1; // Automatically sort items within lists? (1 or 0)<br />function move(fbox,tbox) {<br />for(var i=0; i<fbox.options.length; i++) {<br />if(fbox.options[i].selected && fbox.options[i].value != "") {<br />var no = new Option();<br />no.value = fbox.options[i].value;<br />no.text = fbox.options[i].text;<br />tbox.options[tbox.options.length] = no;<br />fbox.options[i].value = "";<br />fbox.options[i].text = "";<br />}<br />}<br />BumpUp(fbox);<br />if (sortitems) SortD(tbox);<br />}<br />function BumpUp(box) {<br />for(var i=0; i<box.options.length; i++) {<br />if(box.options[i].value == "") {<br />for(var j=i; j<box.options.length-1; j++) {<br />box.options[j].value = box.options[j+1].value;<br />box.options[j].text = box.options[j+1].text;<br />}<br />var ln = i;<br />break;<br /> }<br />}<br />if(ln < box.options.length) {<br />box.options.length -= 1;<br />BumpUp(box);<br /> }<br />}<br />function SortD(box) {<br />var temp_opts = new Array();<br />var temp = new Object();<br />for(var i=0; i<box.options.length; i++) {<br />temp_opts[i] = box.options[i];<br />}<br />for(var x=0; x<temp_opts.length-1; x++) {<br />for(var y=(x+1); y<temp_opts.length; y++) {<br />if(temp_opts[x].text > temp_opts[y].text) {<br />temp = temp_opts[x].text;<br />temp_opts[x].text = temp_opts[y].text;<br />temp_opts[y].text = temp;<br />temp = temp_opts[x].value;<br />temp_opts[x].value = temp_opts[y].value;<br />temp_opts[y].value = temp;<br /> }<br /> }<br />}<br />for(var i=0; i<box.options.length; i++) {<br />box.options[i].value = temp_opts[i].value;<br />box.options[i].text = temp_opts[i].text;<br /> }<br />}