一行代码实现Select列表选中行的上移下移

    function UP()
    {
        var selected = $("#list_des :selected");
        if (selected.get(0).index != 0) {//选中项不能为第一个
            selected.prev().before(selected);
   
        }
        else { return;}
    }
    function Down()
    {
        var selected = $("#list_des :selected");
        var lastoptionindex = $("#list_des option").length;//最后一个option下标   
        var selectoptionindex = (selected.get(0).index+1);//选中option的下标
        if (lastoptionindex != selectoptionindex)//选中项不能为最后一个
        {
            selected.next().after(selected);
        }
        else {
            return;
        }       
    }

 


版权声明:本文为qq_40138785原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。