<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="Generator" content="EditPlus®"> | |
<meta name="Author" content=""> | |
<meta name="Keywords" content=""> | |
<meta name="Description" content=""> | |
<title>Document</title> | |
<script> | |
function removeLeft(){ | |
//找到当前选中的option | |
var lefeSelect = document.getElementById("left"); | |
var selectedIndex = lefeSelect.selectedIndex; | |
var selectedOption = lefeSelect.options[selectedIndex]; | |
//找到右边的select | |
var rightSelect = document.getElementById("right"); | |
rightSelect.add(selectedOption,null); | |
} | |
function removeLeftAll(){ | |
//left的所有option,都移动right | |
var lefeSelect = document.getElementById("left"); | |
//找到右边的select | |
var rightSelect = document.getElementById("right"); | |
var length =lefeSelect.options.length; | |
for(var i=0;i<length;i++){ | |
rightSelect.add(lefeSelect.options[0]); | |
} | |
} | |
</script> | |
</head> | |
<body> | |
<table align="center"> | |
<tr> | |
<td> | |
<select size="10" id="left"> | |
<option>选项1</option> | |
<option>选项2</option> | |
<option>选项3</option> | |
<option>选项4</option> | |
<option>选项5</option> | |
<option>选项6</option> | |
<option>选项7</option> | |
<option>选项8</option> | |
<option>选项9</option> | |
</select> | |
</td> | |
<td> | |
<input type="button" value="--->" onclick="removeLeft()"/><br/> | |
<input type="button" value="===>" onclick="removeLeftAll()"/><br/> | |
</td> | |
<td> | |
<select size="10" id="right"> | |
</select> | |
</td> | |
</tr> | |
</table> | |
</body> | |
</html> | |
时间: 2024-10-25 17:55:44