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>
<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>
<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>
<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>