当前位置: 代码迷 >> Web前端 >> select 上下移动
  详细解决方案

select 上下移动

热度:265   发布时间:2012-09-07 10:38:15.0
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>

<BODY>
<table>
<tr>
<td>
  <select id="L" size=10>

  </select>
  </td>
  <td>
  <input type="button" value="<<" onclick="addLeft()"><br><input type="button" onclick="addRitht()" value=">>">
  </td>
   <td>
  <select id="R" size=10>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
  </select>
  </td>
</tr>
<SCRIPT LANGUAGE="JavaScript">
<!--
function addLeft(){
var v = document.getElementById("R");
var index=v.selectedIndex; //序号,取当前选中选项的序号
if(index==-1){
alert("请选择要添加项!");
return;
}

var val = v.options[index].value;
var name = v.options[index].text;
if(check(val,"L")==1)
return;
var L = document.getElementById("L");
L.options.add(new Option(name,val));
}
function addRitht(){
var v = document.getElementById("L");
var index=v.selectedIndex; //序号,取当前选中选项的序号
if(index==-1){
alert("请选择要取消项!");
return;
}
v.options.remove(index);
}
function check(val,name){
var obj = document.getElementById(name);
var newVal = -1;
for(var i=0;i<obj.options.length;i++){
newVal = obj.options[i].value;
if(val==newVal){
alert("该项已存在!");
return 1;
}
}
return 0;
}
//-->
</SCRIPT>
</BODY>
</HTML>
  相关解决方案