zoukankan      html  css  js  c++  java
  • select的option选项左右移动

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            #choice,#box_L,#box_R{
                display: inline-block;
            }
            #choice{
                top: 20px;
            }
        </style>
    </head>
    <body>
    
        <div id="box_L">
            <select id="left" multiple size="10">
                <option>请选:</option>
                <option>选项2</option>
                <option>选项3</option>
                <option>选项4</option>
                <option>选项5</option>
                <option>选项6</option>
            </select>
        </div>
    <div id="choice">
        <input type="button" value="------>" onclick="adds()"><br>
        <input type="button" value="======>" onclick="addall()"><br>
        <input type="button" value="<------" onclick="restore()"><br>
        <input type="button" value="<======" onclick="allrestore()"><br>
    </div>
    
        <div id="box_R">
            <select id="right" multiple size="10">
            <option>请选:</option>
            </select>
        </div>
    </body>
    <script>
    
        var left = document.getElementById("left");
        var right = document.getElementById("right");
    
        function adds() {
            var options = left.children;
            for(var i =0;i<options.length;i++) {
                if (options[i].selected === true) { //单选
                    options[i].selected = false;   //这个主要是把选项选过去后取消他的选中状态
                    right.appendChild(options[i]);
    
                }
            }
        }
    
        function addall() {
            var options = left.children;
            for(var i =0;i<options.length;i++) {
                right.appendChild(options[i]);
                i--;
            }
        }
        function restore() {
            var options = right.children;
            for (var i=0;i<options.length;i++){
                if(options[i].selected ===true){
                    options[i].selected=false;
                    left.appendChild(options[i]);
    
                }
            }
        }
        function allrestore() {
            var options = right.children;
            for(var i =0;i<options.length;i++) {
                left.appendChild(options[i]);
                i--;
            }
        }
    </script>
    </html>
  • 相关阅读:
    修改tableVIewCell里控件的属性
    常用正则表达式
    解决定时器在主线程不工作问题
    iOS App集成Apple Pay
    使用UIDataDetectorTypes自动检测电话、网址和邮箱
    NSDictionary初始化的坑
    关于UIViewController的presentViewController实现
    iOS8以上使用CoreLocation定位
    .xib 创建的文件 [self.view bringSubviewToFront:XXX];不好用
    socket通讯----GCDAsyncSocke 解读
  • 原文地址:https://www.cnblogs.com/TKOPython/p/12839743.html
Copyright © 2011-2022 走看看