Home > Article > Web Front-end > How to implement left and right movement of drop-down menu in js (code)
The content of this article is about how to implement the left and right movement of the drop-down menu (code) in js. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> <script> //flag标实为全部移动(true) 还是选择性移动(false) function mymove(flag,lid,rid){ var leftobj = document.getElementById(lid);//得到左边select元素对象 var rightobj = document.getElementById(rid);//得到右边select元素对象 for( var i = 0 ; i < leftobj.options.length ; i++ ){ if(flag){ rightobj.appendChild(leftobj.options[i]); i--; }else{ if( leftobj.options[i].selected ){ rightobj.appendChild(leftobj.options[i]); i--; } } } } </script> </head> <body> <input type="button" value="全部左移" onclick="mymove(true,'rightid','leftid')"/> <input type="button" value="左移" onclick="mymove(false,'rightid','leftid')"/> <input type="button" value="右移" onclick="mymove(false,'leftid','rightid')"/> <input type="button" value="全部右移" onclick="mymove(true,'leftid','rightid')"/> <hr> <select size="6" multiple="multiple" style="width: 50px; height: 120px;" id="leftid"> <option>武汉</option> <option>北京</option> <option>上海</option> <option>广州</option> <option>杭州</option> <option>黄石</option> </select> <select size="6" multiple="multiple" style="width: 50px; height: 120px; margin-left: 100px;" id="rightid"> </select> </body></html>
Related recommendations:
How to implement concatenated addback() and end() in jquery (code)
An example of using template template engine in js (code)
Implementation and usage of out-of-order image preloading in jquery
The above is the detailed content of How to implement left and right movement of drop-down menu in js (code). For more information, please follow other related articles on the PHP Chinese website!