dom操作例子

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <script src="Scripts/jquery-1.8.2.min.js"></script>
    <script type ="text/javascript">
        $(function () {
            $("#btnToLeft").click(function () {
                $("#sell option:selected").appendTo("#selr"); //如果添加的节点在dom树那么则直接会移动过去
                //右侧排序 按照value的值进行排序
                $("#selr option").sort(function (x, y) {
                    return parseInt(x.value) - parseInt(y.value);
                    //倒序 return parseInt(y.value) - parseInt(x.value);
                }).appendTo("#selr");
            });
        });
    </script>
</head>
<body>
    <select id="sell" multiple ="multiple">
        <option value ="1">中国</option>
         <option value ="2">德国</option>
         <option value ="3">美国</option>
         <option value ="4">意大利</option>
         <option value ="5">英国</option>
    </select>
    <div >
        <input type ="button" id ="btnToLeft" value ="-->" />
    </div>
    <select id="selr" multiple ="multiple">

    </select>
</body>
</html>

  

posted @ 2014-06-13 23:46  编程猴子  阅读(122)  评论(0编辑  收藏  举报