Click the button to move the form element around

Source: Internet
Author: User

HTML
<! DOCTYPE html>
  <meta charset= "UTF-8" >
  <title> Mobile Option</title>
  <style type= "Text/css" >
  Select {
  width:200px;
  }
?
  . Box {
  Float:left;
  }
  </style>
<body>
  <div class= "box" >
  <select size= "8" id= "Left-select" >
  <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>
  </select>
  <br>
  <button id= "left_up" > Move Up </button>
  <button> Move Down </button>
  <button id= "right" > moving to the left </button>
  <button id= "Right_all" > All right Shift </button>
  </div>
  <div class= "box" >
  <select size= "8" id= "Right-select" >
  <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>
  </select>
  <br>
  <button> Move Up </button>
  <button> Move Down </button>
  <button> Move left </button>
  <button> left shift all </button>
  </div>
  <script src= "./js/Mobile Option.js" ></script>
</body>

JavaScript
(function () {
  var leftselect = document.getElementById (' Left-select ');
  var rightselect = document.getElementById (' Right-select ');
  var leftupbtn = document.getElementById (' left_up ');
  var rightbtn = document.getElementById (' right ');
  var rightallbtn = document.getElementById (' Right_all ');
?
  Leftupbtn.onclick = function () {
  var index = Leftselect.selectedindex;
  //If option is not selected in Select, subsequent operations are not performed
  if (index!==-1) {
  var option = Leftselect.options[index];
?
  if (index = = = 0) {
  leftselect.appendchild (option);
  } else {
  leftselect.insertbefore (option, leftselect.options[index-1]);
  }
  }
  };
?
  Rightbtn.onclick = function () {
  var index = Leftselect.selectedindex;
  if (index!==-1) {
  var option = Leftselect.options[index];
?
  rightselect.appendchild (option);
  }
  };
?
  Rightallbtn.onclick = function () {
For  (var i = 0; i < leftSelect.options.length;) {
  Rightselect.appendchild (Leftselect.options[i]);
  }
  };
})();

Click the button to move the form element around

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.