// 给你补上一个:把列表框中选的选项上移/下移(支持多选)函数
/*******************************************************************************
功能 : 使列表框所选中的项目上移
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]);
}
}
}
下拉列表的上移与下移(转)
最新推荐文章于 2021-06-03 18:33:45 发布