javascript實現的左右選擇框效果代碼_表單特效

來源:互聯網
上載者:User
<!-- 把如下代碼加入<body>地區中 --> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin sortitems = 1; // Automatically sort items within lists? (1 or 0) function move(fbox,tbox) { for(var i=0; i<fbox.options.length; i++) { if(fbox.options[i].selected && fbox.options[i].value != "") { var no = new Option(); no.value = fbox.options[i].value; no.text = fbox.options[i].text; tbox.options[tbox.options.length] = no; fbox.options[i].value = ""; fbox.options[i].text = ""; } } BumpUp(fbox); if (sortitems) SortD(tbox); } function moveall(fbox,tbox) { for(var i=0; i<fbox.options.length; i++) { if(fbox.options[i].value != "") { var no = new Option(); no.value = fbox.options[i].value; no.text = fbox.options[i].text; tbox.options[tbox.options.length] = no; fbox.options[i].value = ""; fbox.options[i].text = ""; } } BumpUp(fbox); if (sortitems) SortD(tbox); } function BumpUp(box) { for(var i=0; i<box.options.length; i++) { if(box.options[i].value == "") { for(var j=i; j<box.options.length-1; j++) { box.options[j].value = box.options[j+1].value; box.options[j].text = box.options[j+1].text; } var ln = i; break; } } if(ln < box.options.length) { box.options.length -= 1; BumpUp(box); } } function SortD(box) { var temp_opts = new Array(); var temp = new Object(); for(var i=0; i<box.options.length; i++) { temp_opts[i] = box.options[i]; } for(var x=0; x<temp_opts.length-1; x++) { for(var y=(x+1); y<temp_opts.length; y++) { if(temp_opts[x].text > temp_opts[y].text) { temp = temp_opts[x].text; temp_opts[x].text = temp_opts[y].text; temp_opts[y].text = temp; temp = temp_opts[x].value; temp_opts[x].value = temp_opts[y].value; temp_opts[y].value = temp; } } } for(var i=0; i<box.options.length; i++) { box.options[i].value = temp_opts[i].value; box.options[i].text = temp_opts[i].text; } } // End --> </script> <form ACTION="" METHOD="POST"> <table border="0"> <tr> <td><select multiple size="5" name="list1" > <option value="11"> item 1.1 </option> <option value="12"> item 1.2 </option> <option value="13"> item 1.3 </option> </select></td> <td> <input type="button" value=" > " onclick="move(this.form.list1,this.form.list2)" name="B1"> <input type="button" value=" < " onclick="move(this.form.list2,this.form.list1)" name="B2"> <input type="button" value=" >> " onclick="moveall(this.form.list1,this.form.list2)" name="B3"> <input type="button" value=" << " onclick="moveall(this.form.list2,this.form.list1)" name="B4"> </td> <td><select multiple size="5" name="list2" > <option value="21"> item 2.1 </option> <option value="22"> item 2.2 </option> <option value="23"> item 2.3 </option> </select></td> </tr> </table> </form>
[Ctrl+A 全選 注:如需引入外部Js需重新整理才能執行]

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.