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.