代码描述:js互换select下拉菜单 option项。js如何互换两个select下拉菜单option项简单介绍实例
有时候需要互换两个select下拉菜单中的option选项,下面就通过代码实例介绍一下如何实现此功能:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.51qianduan.com/" /> <title>51前端</title> <style type="text/css"> select{width:80px;} </style> <script type="text/javascript"> function allsel(from,to){ while(from.selectedIndex!=-1){ var indx=from.selectedIndex; var t=from.options[indx].text; to.options.add(new Option(t)); from.remove(indx); } } window.onload=function(){ oleft=document.getElementById("left"); oright=document.getElementById("right"); oleft.onclick=function(){allsel(document.form1.sel_place2,document.form1.sel_place1);} oright.onclick=function(){allsel(document.form1.sel_place1,document.form1.sel_place2);} } </script> </head> <body> <form name="form1" method="post" action=""> <select name="sel_place1" size="6" multiple id="sel_place1"> <option value="sel1">江苏省</option> <option value="sel2">广东省</option> <option value="sel3">河南省</option> <option value="sel4">吉林省</option> <option value="sel5">浙江省</option> </select> <input name="sure1" type="button" id="left" value="<<"> <input name="sure2" type="button" id="right" value=">>"> <select name="sel_place2" size="6" multiple id="sel_place2"></select> </form> </body> </html>
请绑定手机号,在继续操作
注意:只有绑定手机以后,才可使用网站全部功能