zoukankan      html  css  js  c++  java
  • JS左右框

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
    select {
    70px;
    height: 120px;
    }
    button {
    display: block;
    }
    div {
    vertical-align: top;
    display: inline-block;
    }
    </style>
    </head>
    <body>
    <select id="left" size="10">
    <option value="">张飞</option>
    <option value="">黄忠</option>
    <option value="">关羽</option>
    <option value="">赵云</option>
    <option value="">马超</option>
    </select>
    <div>
    <button onclick="singleToRight()">></button>
    <button onclick="allToRight()">>></button>
    <button onclick="singleToLeft()"><</button>
    <button onclick="allToLeft()"><<</button>
    </div>
    <select id="right" size="10"></select>

    <script>
    var leftEle = document.getElementById("left");
    var rightEle = document.getElementById("right");
    function singleToRight() {
    var index = leftEle.selectedIndex;//获取被选中的option的位置
    var chosenOption = leftEle.options[index];//获取该option
    rightEle.appendChild(chosenOption);//把该option添加到右边select
    }
    function allToRight() {
    while (leftEle.options.length != 0) {
    rightEle.appendChild(leftEle.options[0]);
    }
    }
    function singleToLeft() {
    var index = rightEle.selectedIndex;//获取被选中的option的位置
    var chosenOption = rightEle.options[index];//获取该option
    leftEle.appendChild(chosenOption);//把该option添加到左边select
    }
    function allToLeft() {
    while (rightEle.options.length != 0) {
    leftEle.appendChild(rightEle.options[0]);
    }
    }
    </script>
    </body>
    </html>

  • 相关阅读:
    Djnago中缓存配置(redis配置案例)
    HDU-4717 The Moving Points 三分
    HDU-4716 A Computer Graphics Problem 水题
    HDU-2686 Matrix 多进程DP
    [转]手动开平方的简易方法
    [转]树链剖分
    HUOJ-10857 最大的面积 凸包+DP
    Bnuoj-29359 Deal with numbers 线段树
    HDU-4283 You Are the One 区间DP
    BNUOJ-26586 Simon the Spider 最小生成树+枚举
  • 原文地址:https://www.cnblogs.com/gujinshu-wangdan/p/5574073.html
Copyright © 2011-2022 走看看