標籤:索引 左右移動 cal 分享 左移 賦值 藍色 技術 end
<body>
<select id="s1" size="10" >
<option>紅色</option>
<option>綠色</option>
<option>藍色</option>
<option>黑色</option>
<option>白色</option>
</select>
<select id="s2" size="10" >
<option>蘋果</option>
<option>香蕉</option>
<option>桃子</option>
<option>梨</option>
<option>橙子</option>
</select><br />
<input type="button" id="t1" value="右移" />
<input type="button" id="t2" value="左移" />
<script>
document.getElementById("t1").onclick=function(){ -----右移
var op=document.getElementById("s1").selectedOptions;---------將選中的資料賦值給op
document.getElementById("s2").appendChild(op[0]); ------表示選中的資料中索引值為0
document.getElementById("s1").removeChild(op[0]);
}
document.getElementById("t2").onclick=function(){ ----左移
var op=document.getElementById("s2").selectedOptions;
document.getElementById("s1").appendChild(op[0]);
document.getElementById("s2").removeChild(op[0]);
}
</script>
</body>
列表左右移動 2017-03-23