Small DOM exercises, data movement between two tables, dom tables

Source: Internet
Author: User

Small DOM exercises, data movement between two tables, dom tables

This article describes how to move data between two tables. The table on the left is moved to the right, and the table on the left disappears.

<Head>
  <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
  <Title> </title>
  <Style type = "text/css">
  Select {
  Width: 100px;
  Position: relative;
  Float: left;
  }
   
  # Div-out {
  Width: 100px;
  Position: relative;
  Float: left;
  Height: 113px;
  /* Border: 1px solid black ;*/
  }
   
  # Div-in {
  Width: 50px;
  /* Border: 1px solid red ;*/
  Margin: 0px auto;
  }
   
  Input {
  Margin-top: 22px;
  Width: 50px;
  }
  </Style>
  </Head>
   
  <Body>
  <Select id = "s1" size = "7" multiple = "multiple">
  <Option> AAA </option>
  <Option> BBB </option>
  <Option> CCC </option>
  <Option> DDD </option>
  <Option> EEE </option>
  </Select>
  <Div id = "div-out">
  <Div id = "div-in">
  <Input type = "button" value = ">" onclick = "toright ()"/>
  <Input type = "button" value = "<" onclick = "toleft ()"/>
  </Div>
  </Div>
  <Select id = "s2" size = "7" multiple = "multiple"> </select>
  </Body>
   
  </Html>
  <Script type = "text/javascript">
  Var opt = document. getElementById ("s1"). options;
   
  Function toright (){
  For (var I = 0; I <opt. length; I ++ ){
  If (opt [I]. selected ){
  // Var opt_temp = document. createElement ("option ");
  // Opt_temp.innerText = opt [I]. text;
  // Alert (opt [I]. text );
  Document. getElementById ("s2"). appendChild (opt [I]);
  // Document. getElementById ("s1"). removeChild (opt [I]);
  I --;
  }
  }
  }
  </Script>

This is to move to the right, and to the left.

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.