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

俺的小作品:根据下拉列表动态在列表框中显示,并实现2个列表框互斥选择

答案:具体功能用一下就知道了,在下拉框中选择一个,左边的列表框就显示相应的值,点那4个按钮能够实现左右2个列表框选项互相排斥,很好玩的。。估计大家开发的时候经常要用到,所以就帖上来了。

代码如下:
<style>
td,select,input{font-size:9pt}
</style>
<script>
var subcat = new Array();                                      //  下拉列表数组定义
    subcat[0] = new Array("计划采购员B","2","cs101");
    subcat[1] = new Array("仓库管理员B","2","cs111");
    subcat[2] = new Array("仓库管理员","1","111");
    subcat[3] = new Array("门市管理员","1","122");
    subcat[4] = new Array("计划审批员","1","MASTER");
    subcat[5] = new Array("计划审批员B","2","cs100");
    subcat[6] = new Array("计划采购员","1","103");
    subcat[7] = new Array("统计员","1","李尚英");
    subcat[8] = new Array("统计员B","2","cs133");
                                                        //   这个数组可以根据实际需要用程序继续添加元素
var onecount=subcat.length;
var c=0;d=0;                                            //     2个select的optoins的索引位置...

function moveto2(fn,s1,s2)                                //     ">>" Button function
{
    fs1=eval(fn+"."+s1);                                //      formName1.SelectName1
    fs2=eval(fn+"."+s2);
    d=fs2.options.length;
    for(i=0;i<fs1.options.length;i++)
        {
            var myOption = new

            Option(fs1.options[i].innerText,fs1.options[i].value);  

            fs2.options[d]=myOption ;
            fs2.options[d].selected=true;
            fs1.options[i].selected=true;
            d++;
        }
    k=0;
    while(k<fs1.options.length)
        {
            fs1.remove(k);
            c--;
        }
}

function moveto1(fn,s1,s2)    //    "<<" Button
{
   fs1=eval(fn+"."+s1);
   fs2=eval(fn+"."+s2);
   c=fs1.options.length;
   for(i=0;i<fs2.options.length;i++)
      {
            var myOption = new

            Option(fs2.options[i].innerText,fs2.options[i].value);  

            fs1.options[c]=myOption ;
            fs1.options[c].selected=true;
            fs2.options[i].selected=true;
            c++;
      }
   k=0;
   while(k<fs2.options.length)
        {
            fs2.remove(k);
            d--;
        }
}

function move1to2(fn,s1,s2)    //      ">" Button
{
    fs1=eval(fn+"."+s1);
    fs2=eval(fn+"."+s2);
    c=fs1.options.length;
    d=fs2.options.length;
    for(i=0;i<fs1.options.length;i++)
        {
            if(fs1.options[i].selected)
                {    
                    var myOption = new
Option(fs1.options[i].innerText,fs1.options[i].value);  

                    fs2.options[d]=myOption ;
                    fs2.options[d].selected=true;
                    d++;
                }
        }
    k=0;
    while(k<fs1.options.length+3)                             //   这里为什么要+3,我也不知道
        {
            del(fn,s1,s2);
            k++;
        }
}

function del(fn,s1,s2)                                         //   删除选择的列表项目
{
  &nb

上一个:认识DHTML中的“行为”组件(读后大有启发)
下一个:to hiller:利用脚本控制表格单元的内容(原创)

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