select 从左向右添加

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
 </HEAD>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>

<script language="javascript">
<!-- 从左到右添加。。。。。。。从右往左添加-->
function trans(from,to){
fromList = eval('document.forms[0].'+ from);
toList = eval('document.forms[0].'+ to);
if(toList.options.length>0&&toList.options[0].value=="hello"){
toList.options.length=0;
}
for(var i=0;i <fromList.options.length;i++){
current = fromList.options[i];
var flag = false;
if(current.selected){
flag=true;
if(current.value=="hello"){
return ;
}
txt=current.text;
val=current.value;
toList.options[toList.length]=new Option(txt,val);
fromList.options[i] = null;
i--;
}

}
}

<!--向上移动 -->
function forword (up){
high=eval('document.forms[0].'+up);
for(var i=1;i <high.options.length;i++){
current = high.options[i];
yes = high.options[i-1];
var flag =false;
if(current.selected){
flag=true;
txt1=yes.text;
var1=yes.value;

txt =current.text;
val =current.value;
high.options[i] =new Option(txt1,var1);
high.options[i-1]=new Option(txt,val);
}
}
}
<!--向下移动 -->
function comeback(down){
high=eval('document.forms[0].'+down);
if(toList.options.length>0&&toList.options[0].value=="temp"){
toList.options.length=0;
}
for(var i=0;i <high.options.length;i++){
current = high.options[i];
yes = high.options[i+1];
if(current.selected){
txt1=yes.text;
var1=yes.value;
txt =current.text;
val =current.value;
high.options[i] =new Option(txt1,var1);
high.options[i+1]=new Option(txt,val);
high.selectedIndex=current.selecteIndex+1;
}
}
}
<!-- 全部从左到右-->
function eachother(from,to){
fromList = eval('document.forms[0].'+ from);
toList = eval('document.forms[0].' + to);
if(toList.size>=0){
var a;
var b;
var x;
var y;
var current;
var yeah;
for(var z=0;z <toList.length;z++){
yeah=toList.options[z];
a=yeah.text;
b=yeah.value;
toList.options[z] = new Option(a,b);
}
for(var i =0;i <fromList.length;i++){ //判断 以前的是否有值
current = fromList.options[i];
x=current.text;
y=current.value;
toList.options[i] = new Option(x,y);
}
fromList.options.length=0;
}else {
for(var i =0;i <fromList.length;i++){
current = fromList.options[i];
x=current.text;
y=current.value;
toList.options[i] = new Option(x,y);
}
fromList.options.length=0;
}
}
<!--全部从右往左 -->
function eachother2(from,to){
fromList = eval('document.forms[0].'+ from);
toList = eval('document.forms[0].' + to);
if(toList.options.length>0&&toList.options[0].value=="hello"){
toList.options.length=0;
}
for(var i =0;i <fromList.length;i++){
current = fromList.options[i];
x=current.text;
y=current.value;
toList.options[i] = new Option(x,y);
//fromList.options[i] = null;
}
fromList.options.length=0;
}
</script>

</head>
<body>
<form id="form1" name="form1" method="post" action="">
<table width="975" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td height="64" colspan="6" valign="top"> <table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="975" height="64">&nbsp; </td>
</tr>
</table> </td>
</tr>
<tr>
<td width="147" height="350" valign="top"> <table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="147" height="350" valign="top"> <!--DWLayoutEmptyCell-->&nbsp; </td>
</tr>
</table> </td>
<td width="286" valign="top"> <table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="286" height="350" valign="top">
<select name="select1" style="width:100%; height:100%;" multiple="multiple" size="5">
<option value="1">通知 </option>
<option value="2">常用网址 </option>
<option value="3">网上调查 </option>
<option value="4">最新上传文件 </option>
<option value="5">快捷方式 </option>
<option value="6">桌面便笺 </option>
<option value="7">公司通讯录 </option>
<option value="8">公共通讯录 </option>
<option value="9">工作计划 </option>
<option value="10">已收文件 </option>
<option value="11">今日工作安排 </option>
<option value="12">短消息 </option>
<option value="13">个人通讯录 </option>
</select>
</td>
</tr>
</table> </td>
<td width="46" valign="top"> <table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="159" height="350" valign="top"> <table width="45" border="0">
<tr>
<td width="39" height="57"> <input type="button" name="Submit2" value="从左到右;" onclick="javascript:trans('select1','select2')" /> </td>
</tr>
<tr>
<td height="58"> <input type="button" name="Submit" value="从右到左" onclick="javascript:trans('select2','select1')" /> </td>
</tr>
<tr>
<td height="74"> <input type="button" name="Submit6" value="全部向右" onclick="eachother('select1','select2')" /> </td>
</tr>
<tr>
<td height="72"> <input type="button" name="Submit5" value="全部向左" onclick="eachother('select2','select1')"/> </td>
</tr>
</table>
</td>
</tr>
</table> </td>
<td width="364" valign="top"> <table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="364" height="350" valign="top"> <select name="select2" style="width:100%; height:100%;"multiple="multiple" size="5">
<option value="temple">从左边区域选择 </option>
</select> </td>
</tr>
</table> </td>
<td width="51" valign="top"> <table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="62" height="350" valign="top"> <table width="84" height="351" border="1">
<tr>
<td width="74" height="91"> <input type="button" name="Submit3" value="向上" onclick="forword('select2')" /> </td>
</tr>
<tr>
<td height="60"> <input type="button" name="Submit4" value="向下" onclick="comeback('select2')"/> </td>
</tr>
<tr>
<td height="76">&nbsp; </td>
</tr>
<tr>
<td>&nbsp; </td>
</tr>
</table> </td>
</tr>
</table> </td>
<td width="81">&nbsp; </td>
</tr>
</table>
</form>
</body>
</HTML>

posted @ 2008-08-22 15:09  XGU_Winner  阅读(211)  评论(0)    收藏  举报