`
liqiupeng19840929
  • 浏览: 38488 次
  • 性别: Icon_minigender_2
  • 来自: 河北.
最近访客 更多访客>>
社区版块
存档分类
最新评论

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

 
阅读更多
 

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

/*******************************************************************************
功能        使列表框所选中的项目上移
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]);
                }
        }
}

分享到:
评论

相关推荐

    Vue中列表子项实现上移或下移.rar_stopxad_vue

    实现下拉列表,在页面上的上下移动位置,以便用户自定义列表的显示顺序,。

    LabVIEW的组合框

    单击右侧“Insert”按钮添加项,单击“删除”按钮删除选中的项,单击“上移”或“下移”按钮用来上移或下移选中项在控件中显示的位置。勾选复选框“允许在运行时有未定义值”表示可以有没有赋值的项存在。  图1 ...

    EDA/PLD中的LabVIEW的组合框

    单击右侧“Insert”按钮添加项,单击“删除”按钮删除选中的项,单击“上移”或“下移”按钮用来上移或下移选中项在控件中显示的位置。勾选复选框“允许在运行时有未定义值”表示可以有没有赋值的项存在。  图1 ...

    如何将PPT转word

    最后,还可以使用“大纲”工具栏,利用“升级”、“降级”、“上移”、“下移”等按钮进一步进行调整。 反之,如果是将PowerPoint演示文稿转换成Word文档,同样可以利用“大纲”视图快速完成。方法是将光标定位在除...

    office2003培训教程.pptx

    按键 移动插入点 左移一个字符 " 右移一个字符 上移一行 下移一行 Page Down 上移一屏 Page Up 下移一屏 Home 移到当前行的开头 End 移到当前行的末尾 Ctrl + Home 移到文档的开头 Ctrl + End 移到文档的末尾 光标...

    《程序天下:JavaScript实例自学手册》光盘源码

    6.5 从一个下拉列表往另一个下拉列表添加内容 6.6 改变列表项的上下顺序 6.7 给下拉框数据分组 6.8 获取列表框的选择 6.9 类IE下拉框 6.10 下拉框式邮件发送 6.11 获取多选框的选择项 6.12 手动调整的列表框 6.13 ...

    程序天下:JavaScript实例自学手册

    6.5 从一个下拉列表往另一个下拉列表添加内容 6.6 改变列表项的上下顺序 6.7 给下拉框数据分组 6.8 获取列表框的选择 6.9 类IE下拉框 6.10 下拉框式邮件发送 6.11 获取多选框的选择项 6.12 手动调整的列表框 6.13 ...

    GPRS控制卡 软件 GS7020B

    如果GS7020B 与显示屏共用一个电源,应使用不超过1 米的电源线直接 从电源上引出,请勿使用经过若干显示单元板串接的电源。 注意:如果已经将显示单元板通过排线连接到了GS7020B,则一定要保 证显示屏单元板与GS7020...

    易语言程序免安装版下载

    修改扩展界面支持库三,解决单击卷帘菜单后导致日期框不能弹出下拉窗口的BUG。 4. 修改XP风格支持库,解决GDI资源泄露,以及在使用通用组件库六时组合框标题出现重影的BUG。 5. 修改扩展界面支持库一,解决树形框...

    protel2004封装

    单击*1.PcbLib(被复制的封装元件要复制到的元件库),将*1.PcbLib作为当前被编辑的文件,用鼠标右键点封装元件列表最上面的空白处,在下拉菜单单击“Paste”,然后保存即可; 方法二、单击*.PcbLib(被复制的封装元件...

    applem2_20120610苹果引擎配套工具,内有登陆器配置

    5、登陆器列表配置增加分组上移下移及服务器分区上移下移功能 6、合区工具加入文本合并功能 [2012-03-28] 1、支持盛大最新客户端 2、支持盛大最新装备及特效 3、增加属性转移触发[@MOVEABILITY_OK]和[@MOVEABILITY_...

Global site tag (gtag.js) - Google Analytics