首页 > 其他 > 详细

左侧下拉框中的内容点击按钮移到右侧下拉框

时间:2014-03-11 07:51:09      阅读:647      评论:0      收藏:0      [点我收藏+]

<form name=”myform” method=”post” >

<select name=”hostlist1” size=”15” multiple=”multiple”>

<option >…..</option>

</select>
< select name=”hostlist2” size=”15” multiple=”multiple”>

</select>

<input name=”addbutton” type=”button” value=”添加” onclick=”dealAgent(document.myform.hostlist2, document.myform.hostlist1)”/>

<input name=”addbutton” type=”button” value=”删除” onclick=”dealAgent(document.myform.hostlist1, document.myform.hostlist2)”/>

<input type=”button” value=”上移”onclick="changepos(hostlist2,-1)" type="button">

<input type=”button” value=”下移”onclick="changepos(hostlist2,1)" type="button">

<input name=”hostvalue” type=”hidden”/>

</form>

<script>

function dealAgent(hostlist1,hostlist2)

{

    for(var i=0;i<hostlist1.options.length;i++)

    {

       if(hostlist1.options[i].selected)

       {

           var host=hostlist1.options[i];

           hostlist2.options.add(new Option(host.text,host.value));

           hostlist1.remove(i);

           i=i-1;

       }

    }

    document.myform.hostvalue.value=getValue(document.myform.hostlist2);

    //document.myform.hostvalue.value=getValue(document.myform.hostlist2);

}

function getValue(hostlist2){

    var hostValue="";

    if(hostlist2.options.length!=0)

       hostValue+=hostlist2.options[0].value;

    for(var i=1;i<hostlist2.options.length;i++){

       hostValue +=","+hostlist2.options[i].value;

    }

    return hostValue;

    }

function changepos(obj,index)

{

if(index==-1){

if (obj.selectedIndex>0){

obj.options(obj.selectedIndex).swapNode(obj.options(obj.selectedIndex-1))

}

}

else if(index==1){

if (obj.selectedIndex<obj.options.length-1){

obj.options(obj.selectedIndex).swapNode(obj.options(obj.selectedIndex+1))

}

}

}

</script>

左侧下拉框中的内容点击按钮移到右侧下拉框,布布扣,bubuko.com

左侧下拉框中的内容点击按钮移到右侧下拉框

原文:http://www.cnblogs.com/bmdjing/p/3591147.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!