当前位置:编程学习 > asp >>

两个列表匡内容互相挪来挪去的例子(javascript)

答案:效果见
http://www.e-hld.com/tmp/test.htm

代码:


<HTML>
<HEAD>
<TITLE></TITLE>
<script language="javascript">
function adduser()
    {
    freelength = document.all.freeid.length;
    for (var i=freelength-1;i>=0;i--)
        {
        if (document.all.freeid.options[i].selected)
            {
            var newtext = document.all.freeid.options[i].text;
            var newvalue = document.all.freeid.options[i].value;
            var nowlength = document.all.nowid.length;
            document.all.nowid.options[nowlength] = new Option(newtext,newvalue);
            document.all.freeid.options[i] = null;
            }
        }
    }

function deluser()
    {
    nowlength = document.all.nowid.length;
    for (var i=nowlength-1;i>=0;i--)
        {
        if (document.all.nowid.options[i].selected)
            {
            var newtext = document.all.nowid.options[i].text;
            var newvalue = document.all.nowid.options[i].value;
            var freelength = document.all.freeid.length;
            document.all.freeid.options[freelength] = new Option(newtext,newvalue);
            document.all.nowid.options[i] = null;
            }
        }
    }
</script>
</HEAD>
<BODY BGCOLOR="#ffffff" >
            <table border="1" cellpadding="3" cellspacing="0" style="border-collapse: collapse" bordercolor="#CCCCCC" width="100%">
              <tr>
                <td colspan="2">
                  <table width="90%" border="0" cellspacing="0" cellpadding="0" align="center">
                    <tr>
                        <td>
                        <select name="freeid" multiple size="6" style="width:200px">
                        
                            <option value="1">admin</option>
                        
                        </select>
                        </td>
                        <td valign="center" align="center">
                        <input type="button" class="it" value="添加>>" onclick="adduser()"><br><br>
                        <input type="button" class="it" value="<<删除" onclick="deluser()">
                        </td>
                        <td>
                        <select name="nowid" multiple size="6" style="width:200px">
                        
                            <option value="11">EHLDCIO</option>
                        
                            <option value="15">wanglifeng</option>
                        
                            <option value="16">service</option>
                        
                        </select>
                        </td>
                    </tr>
               &nbs

上一个:七彩渐变条(2):改进版
下一个:送大家一个好东西。。文章发表了。。我公布代码!!

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,