1. 程式人生 > >javascript簡單練習案例

javascript簡單練習案例

function quanaddright() { var s1 = document.getElementById("s1"); var s2 = document.getElementById("s2"); var op = s1.getElementsByTagName("option"); for(var i = 0; i < op.length;) { var o = op[0] //document.writeln(o.innerHTML);
//alert(op.length+"i="+i); s2.appendChild(o); } } function quanaddleft() { var s1 = document.getElementById("s1"); var s2 = document.getElementById("s2"); var op = s2.getElementsByTagName("option"
); for(var i = 0; i < op.length;) { var o = op[0] //document.writeln(o.innerHTML); //alert(op.length+"i="+i); s1.appendChild(o); } } function xuanaddright() {
var s1 = document.getElementById("s1"); var s2 = document.getElementById("s2"); var op = s1.getElementsByTagName("option"); for(var i = 0; i < op.length;) { var o = op[i] if(o.selected) { s2.appendChild(o); } else { i++; } } } function xuanaddleft() { var s1 = document.getElementById("s1"); var s2 = document.getElementById("s2"); var op = s2.getElementsByTagName("option"); for(var i = 0; i < op.length;) { var o = op[i] if(o.selected) { s1.appendChild(o); } else { i++; } } }