两个multiple select 间option互移

<!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 moveRight() {
        var sourceSelect = document.getElementById("sourceSelect"); 
var targetSelect = document.getElementById("targetSelect");  
        while(sourceSelect.options.selectedIndex != -1){
targetSelect.options.add(sourceSelect.options.item(sourceSelect.selectedIndex));
}
    }

function moveLeft() {
        var sourceSelect = document.getElementById("targetSelect"); 
var targetSelect = document.getElementById("sourceSelect");  
        while(sourceSelect.options.selectedIndex != -1){
targetSelect.options.add(sourceSelect.options.item(sourceSelect.selectedIndex));
}
    }
  </script>
</head>
<body>
  <select id="sourceSelect" multiple >
<option value="1">aaa</option>
<option value="2">bbb</option>
<option value="3">ccc</option>
<option value="4">ddd</option>
<option value="5">eee</option>
<option value="6">fff</option>
  </select>

  <a onclick="moveRight();"> >> </a>
  <a onclick="moveLeft();"> << </a>

  
<select id="targetSelect" multiple>

</select>
</body>
</html>

猜你喜欢

转载自towardsfuture.iteye.com/blog/2292096