selected移動

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
 <title></title>
</head>
<body>
<select id="select1" multiple="multiple" style="float:left;">
<option>添加</option>
<option>刪除</option>
<option>修改</option>
<option>查詢</option>
<option>打印</option>
</select>

<input type="button" value=">"  οnclick="move(document.getElementById('select1'),document.getElementById('select2'))"/>
<input type="button" value="<" οnclick="move(document.getElementById('select2'),document.getElementById('select1'))"/>
<input type="button" value=">>" οnclick="moveall(document.getElementById('select1'),document.getElementById('select2'))"/>
<input type="button" value="<<" οnclick="moveall(document.getElementById('select2'),document.getElementById('select1'))"/>

<select id="select2" multiple="multiple">
</select>
</body>
</html>

<script type="text/javascript">
    function move(selectSrc,selectDest) {
        for (var i = 0; i < selectSrc.childNodes.length; i++) {
            var option = selectSrc.childNodes[i];
            if (option.selected == true) {
                selectSrc.removeChild(option);
                selectDest.appendChild(option);
                option.selected = "";
                i--;
            }
        }
    }

    function moveall(selectSrc, selectDest) {
        while (selectSrc.childNodes.length != 0)
        {
            var option = selectSrc.childNodes[0];
            selectSrc.removeChild(option);
            selectDest.appendChild(option);
            option.selected = "";
        }

    }
</script>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章