zoukankan      html  css  js  c++  java
  • js select 实现左右传值.html

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>Untitled Document</title>


    <script language="javascript">
    function addItem(objForm)
    {
    var valueAry=new Array();
    var textAry=new Array();
    var leftElement=objForm.elements["left"];
    var rightElement=objForm.elements["right"];
    var count=0;
    var i,j,k,flag;
    for(i=0;i<leftElement.options.length;i++)
    {
    if(leftElement.options[i].selected)
    {valueAry[count]=leftElement.options[i].value;
    textAry[count]=leftElement.options[i].text;
    count++;
    }
    }
    var count1=rightElement.options.length;
    count1=count1>0?count1:0;
    for(j=0;j<count;j++)
    {
    flag=false;
    for(k=0;k<count1;k++)
    {
    if(rightElement.options[k].text==textAry[j])
    flag=true;
    }
    if(!flag)
    {
    rightElement.options[count1]=new Option(textAry[j],valueAry[j]);
    count1++;
    }
    }
    }
    function subItem(objForm)
    {
    var i;
    var objElement=objForm.elements["right"];
    for(i=objElement.options.length-1;i>=0;i--)
    {
    if(objElement.options[i].selected)
    objElement.options[i]=null;
    }
    }
    function addAllItem(objForm)
    {
    var i;
    var leftElement=objForm.elements["left"];
    for(i=0;i<leftElement.options.length;i++)
    {
    leftElement.options[i].selected=true;
    }
    addItem(objForm);
    }
    function subAllItem(objForm)
    {
    var i;
    var rightElement=objForm.elements["right"];
    for(i=0;i<rightElement.options.length;i++)
    rightElement.options[i].selected=true;
    subItem(objForm);
    }
    </script>

    </head>

    <body>

    <table width="200" cellpadding="0" cellspacing="0" border="0">
    <form>
    <tr>
    <td width="80" rowspan="4">
    <select name="left" style="80px;height:100px;" multiple>
    <option>ITEM1</option>
    <option>ITEM2</option>
    <option>ITEM3</option>
    <option>ITEM4</option>
    <option>ITEM5</option>
    <option>ITEM6</option>
    </select></td>
    <td width="40" height="20" align="center">
    <input type="button" value=" >> " onclick="addItem(this.form);">
    </td>
    <td width="80" rowspan="4" align="right">
    <select name="right" style="80px;height:100px;" multiple>
    </select>
    </td>
    </tr>

    <tr>
    <td width="40" align="center"><input type="button" value=" << " onclick="subItem(this.form)"></td>
    </tr>
    <tr>
    <td width="40" align="center"><input type="button" value="ALL>>" onclick="addAllItem(this.form)"></td>
    </tr>
    <tr>
    <td width="40" align="center"><input type="button" value="<<ALL" onclick="subAllItem(this.form)"></td>
    </tr>
    </form>
    </tr>
    </table>
    </body>
    </html>

  • 相关阅读:
    导出数据到Excel
    VB中导入数据到Excel内容换行
    上传附件导入,确认弹框取消后,无法上传附件
    扫描审核,出错声音报警
    C语言中,隐藏结构体的细节
    C语言 符号的不同意义
    IAR 和 keil 使用外部 SDRAM 的区别
    C语言 ringBuffer 实现
    C语言 malloc 内存泄漏
    STM32 硬件CRC和软件CRC速度比较
  • 原文地址:https://www.cnblogs.com/costa92/p/4054645.html
Copyright © 2011-2022 走看看