追加子元素
1.新创建的元素追加进去
末尾
2.本身列表里的元素,追加进去
剪切
3.其他列表里的元素,追加进去
剪切
这个挺烦的,左右来回追加,石乐志才来写这个= =
<style>
select { width: 100px; height: 150px; } </style><body>
<select name="" id="left" multiple>
<option value="">四月是你的谎言</option> <option value="">言叶之庭</option> <option value="">你的名字</option> <option value="">未闻花名</option> <option value="">秒速五厘米</option> <option value="">月色真美</option></select>
<input type="button" value=">>" id="btn1"/>
<input type="button" value="<<" id="btn2"/> <input type="button" value=">" id="btn3"/> <input type="button" value="<" id="btn4"/><select name="" id="right" multiple>
</select> <script > var left=document.getElementById("left"); var right=document.getElementById("right"); var allRight=document.getElementById("btn1"); var allLeft=document.getElementById("btn2");
var oneRight=document.getElementById("btn3");
var oneLeft=document.getElementById("btn4");allRight.οnclick=function(){
for(var i =0 ; i<left.children.length; i++){
right.appendChild(left.children[i]);
i--;
}
}allLeft.οnclick=function(){
for(var i = 0 ; i <right.children.length; i++){
left.appendChild(right.children[i]);
i--;
}
}oneRight.οnclick=function(){
for(var i = 0 ; i<left.chidren.length; i++){
if(left.chidren[i].selected){
right.appendChild(left.children[i]);
i--;
} } }oneLeft.οnclick=function(){
for(var i = 0 ; i<right.chidren.length; i++){
if(right.chidren[i].selected){
left.appendChild(right.children[i]);
i--;
} } }//封装
allRight.οnclick=function(){end(left,right);
}
function end(a,b){
for(var i = 0 ; i<b.chidren.length; i++){
a.appendChild(b.children[i]);
i--;
}
</script></body>