下拉列表的上移与下移(转)

 

// 给你补上一个:把列表框中选的选项上移/下移(支持多选)函数

/*******************************************************************************
功能        : 使列表框所选中的项目上移
Writer
ClearWind
创建        2007-06-21 15:46:00
函数名        SelectMoveUp
参数1        oSelect 源列表框对象 如: document.getElementById("name")
参数2        isToTop 是否移至选择项到顶端,其它依次下移
           true
为移动到顶端,false反之,默认为false
说明    SelectMoveUp(document.getElementById("name"),true);
*******************************************************************************/

function SelectMoveUp( oSelect,isToTop )
{
        if( isToTop == null ) var isToTop = false; //
默认状态不是移动到顶端

        if( oSelect.multiple ) //
如果是多选
        {
                for( var selIndex=0; selIndex<oSelect.options.length; selIndex++ )
                {
                        if(isToTop) //
如果设置了移动到顶端标志
                        {
                                if( oSelect.options[selIndex].selected )
                                {
                                var transferIndex = selIndex;
                                while(transferIndex > 0 && !oSelect.options[transferIndex - 1].selected)
                                {
                                        oSelect.options[transferIndex].swapNode(oSelect.options[transferIndex - 1]);
                                        transferIndex --;
                                }
                                }
                        }
                        else //
没有设置移动到顶端标志
                        {
                                if(oSelect.options[selIndex].selected)
                                {
                                if(selIndex > 0)
                                {
                                        if(!oSelect.options[selIndex - 1].selected) oSelect.options[selIndex].swapNode(oSelect.options[selIndex - 1]);
                                }
                                }
                        }
                }
        }
        else //
如果是单选
        {
                var selIndex = oSelect.selectedIndex;
                if(selIndex <= 0) return;

                if(isToTop) //
如果设置了移动到顶端标志
                {
                        while(selIndex > 0)
                        {
                                oSelect.options[selIndex].swapNode(oSelect.options[selIndex - 1]);
                                selIndex --;
                        }
                }
                else //
没有设置移动到顶端标志
                {
                        oSelect.options[selIndex].swapNode(oSelect.options[selIndex - 1]);
                }
        }
}

/*******************************************************************************
功能        : 使列表框所选中的项目下移
Writer
ClearWind
创建        2007-06-21 15:56:00
函数名        SelectMoveDown
参数1        oSelect 源列表框对象 如: document.all.name
参数2        isToBottom 是否移至选择项到底端,其它依次下移
           true
为移动到底端,false反之,默认为false
说明    SelectMoveDown(document.all.name,true);
*******************************************************************************/

function SelectMoveDown( oSelect,isToBottom )
{
        if(isToBottom == null) var isToBottom = false; //
默认状态不是移动到顶端

        var selLength = oSelect.options.length - 1;

        if(oSelect.multiple) //
如果是多选
        {
        for(var selIndex=oSelect.options.length - 1; selIndex>= 0; selIndex--)
        {
                if(isToBottom) //
如果设置了移动到顶端标志
                {
                        if(oSelect.options[selIndex].selected)
                        {
                        var transferIndex = selIndex;
                        while(transferIndex < selLength && !oSelect.options[transferIndex + 1].selected)
                        {
                                oSelect.options[transferIndex].swapNode(oSelect.options[transferIndex + 1]);
                                transferIndex ++;
                        }
                        }
                }
                else //
没有设置移动到顶端标志
                {
                        if(oSelect.options[selIndex].selected)
                        {
                        if(selIndex < selLength)
                        {
                                if(!oSelect.options[selIndex + 1].selected) oSelect.options[selIndex].swapNode(oSelect.options[selIndex + 1]);
                        }
                        }
                }
        }
        }
        else //
如果是单选
        {
                var selIndex = oSelect.selectedIndex;

                if(selIndex >= selLength - 1) return;

                if(isToBottom) //
如果设置了移动到顶端标志
                {
                        while(selIndex < selLength - 1)
                        {
                                oSelect.options[selIndex].swapNode(oSelect.options[selIndex + 1]);
                                selIndex ++;
                        }
                }
                else //
没有设置移动到顶端标志
                {
                        oSelect.options[selIndex].swapNode(oSelect.options[selIndex + 1]);
                }
        }
}//
给你补上一个:把列表框中选的选项上移/下移(支持多选)函数

/*******************************************************************************
功能        : 使列表框所选中的项目上移
Writer
ClearWind
创建        2007-06-21 15:46:00
函数名        SelectMoveUp
参数1        oSelect 源列表框对象 如: document.getElementById("name")
参数2        isToTop 是否移至选择项到顶端,其它依次下移
           true
为移动到顶端,false反之,默认为false
说明    SelectMoveUp(document.getElementById("name"),true);
*******************************************************************************/

function SelectMoveUp( oSelect,isToTop )
{
        if( isToTop == null ) var isToTop = false; //
默认状态不是移动到顶端

        if( oSelect.multiple ) //
如果是多选
        {
                for( var selIndex=0; selIndex<oSelect.options.length; selIndex++ )
                {
                        if(isToTop) //
如果设置了移动到顶端标志
                        {
                                if( oSelect.options[selIndex].selected )
                                {
                                var transferIndex = selIndex;
                                while(transferIndex > 0 && !oSelect.options[transferIndex - 1].selected)
                                {
                                        oSelect.options[transferIndex].swapNode(oSelect.options[transferIndex - 1]);
                                        transferIndex --;
                                }
                                }
                        }
                        else //
没有设置移动到顶端标志
                        {
                                if(oSelect.options[selIndex].selected)
                                {
                                if(selIndex > 0)
                                {
                                        if(!oSelect.options[selIndex - 1].selected) oSelect.options[selIndex].swapNode(oSelect.options[selIndex - 1]);
                                }
                                }
                        }
                }
        }
        else //
如果是单选
        {
                var selIndex = oSelect.selectedIndex;
                if(selIndex <= 0) return;

                if(isToTop) //
如果设置了移动到顶端标志
                {
                        while(selIndex > 0)
                        {
                                oSelect.options[selIndex].swapNode(oSelect.options[selIndex - 1]);
                                selIndex --;
                        }
                }
                else //
没有设置移动到顶端标志
                {
                        oSelect.options[selIndex].swapNode(oSelect.options[selIndex - 1]);
                }
        }
}

/*******************************************************************************
功能        : 使列表框所选中的项目下移
Writer
ClearWind
创建        2007-06-21 15:56:00
函数名        SelectMoveDown
参数1        oSelect 源列表框对象 如: document.all.name
参数2        isToBottom 是否移至选择项到底端,其它依次下移
           true
为移动到底端,false反之,默认为false
说明    SelectMoveDown(document.all.name,true);
*******************************************************************************/

function SelectMoveDown( oSelect,isToBottom )
{
        if(isToBottom == null) var isToBottom = false; //
默认状态不是移动到顶端

        var selLength = oSelect.options.length - 1;

        if(oSelect.multiple) //
如果是多选
        {
        for(var selIndex=oSelect.options.length - 1; selIndex>= 0; selIndex--)
        {
                if(isToBottom) //
如果设置了移动到顶端标志
                {
                        if(oSelect.options[selIndex].selected)
                        {
                        var transferIndex = selIndex;
                        while(transferIndex < selLength && !oSelect.options[transferIndex + 1].selected)
                        {
                                oSelect.options[transferIndex].swapNode(oSelect.options[transferIndex + 1]);
                                transferIndex ++;
                        }
                        }
                }
                else //
没有设置移动到顶端标志
                {
                        if(oSelect.options[selIndex].selected)
                        {
                        if(selIndex < selLength)
                        {
                                if(!oSelect.options[selIndex + 1].selected) oSelect.options[selIndex].swapNode(oSelect.options[selIndex + 1]);
                        }
                        }
                }
        }
        }
        else //
如果是单选
        {
                var selIndex = oSelect.selectedIndex;

                if(selIndex >= selLength - 1) return;

                if(isToBottom) //
如果设置了移动到顶端标志
                {
                        while(selIndex < selLength - 1)
                        {
                                oSelect.options[selIndex].swapNode(oSelect.options[selIndex + 1]);
                                selIndex ++;
                        }
                }
                else //
没有设置移动到顶端标志
                {
                        oSelect.options[selIndex].swapNode(oSelect.options[selIndex + 1]);
                }
        }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值