Drop-down list select move from left border to right example _javascript tips

Source: Internet
Author: User
When the page is not finished loading, call the following statement, you will not get the "add" object, the prompt is empty or not object
Copy Code code as follows:

document.getElementById ("Add"). onclick = function () {
Alert ("Hello");
}

Objects that are desirable when used
Copy Code code as follows:

Window.onload = function () {
document.getElementById ("Add"). onclick = function () {
Alert ("Hello");
}
}

Copy Code code as follows:

<script type= "Text/javascript" >
Select to move from left to right
function ToRight () {
var firstelement = document.getElementById ("a");
var secondelement = document.getElementById ("second");
var firstoptionelement = firstelement.getelementsbytagname ("option");
var len = firstoptionelement.length;
for (Var i=0;i<len;i++) {
if (Firstelement.selectedindex!=-1) {//selectedindex is the property of the Select
Secondelement.appendchild (Firstoptionelement[firstelement.selectedindex]);
}
}
}
Move all to the right
function Allright () {
var firstelement = document.getElementById ("a");
var secondelement = document.getElementById ("second");
var firstoptionelement = firstelement.getelementsbytagname ("option");
var len = firstoptionelement.length;
for (Var i=0;i<len;i++) {
Secondelement.appendchild (Firstoptionelement[0]);//option option is indexed to 0 when selected
}
}
Double-click to move to the right
function db () {
*//Method One
var firstelement = document.getElementById ("a");
var secondelement = document.getElementById ("second");
var firstoptionelement = firstelement.getelementsbytagname ("option");
var len = firstoptionelement.length;
for (Var i=0;i<len;i++) {
if (Firstelement.selectedindex!=-1) {//selectedindex is the property of the Select
Secondelement.appendchild (Firstoptionelement[firstelement.selectedindex]);
}
} */
Method Two
var firstelement = document.getElementById ("a");
var secondelement = document.getElementById ("second");
Secondelement.appendchild (Firstelement[firstelement.selectedindex]);
}

</script>

<style type= "Text/css" >

</style>
<body>
<table width= "285" height= "169" border= "0" align= "left" >
<tr>
&LT;TD width= "126" >
<select name= "The" "size=" multiple= "multiple" id= "a", "ondblclick=" "db ()" >
<option value= "1" > Option 1</option>
<option value= "2" > Option 2</option>
<option value= "3" > Option 3</option>
<option value= "4" > Option 4</option>
<option value= "5" > Option 5</option>
<option value= "6" > Option 6</option>
</select>
</td>
&LT;TD width= "valign=" "Middle" >
<input id= "Add" name= "Add" type= "button" value= "---->" onclick= "toright ()"/>
<input id= "Add_all" name= "Add_all" type= "button" value= "==>" onclick= "Allright" ()/>
</td>
&LT;TD width= "127" align= "left" >
<select name= "Second" size= "multiple=" "multiple" id= "second" >
<option value= "option 8" > Options 8</option>
</select>
</td>
</tr>
</table>
</body>

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.