Js functions for adjusting the select position, move up, move down, move to the top, move to the end, and share with you several js functions written in the project, the function is to move the option position in the select statement using js. The Code is as follows // sort: Move Up
Function Up ()
...{
Var sel = document. getElementById ("selectCheck"); // obtain select
Var nIndex = sel. selectedIndex; // index of the select item to be operated
Var nLen = sel. length; // total number of select projects
If (nLen <1) | (nIndex = 0) return;
If (nIndex <0)
...{
Alert ("select a selected button to move! ");
Return;
}
Var sValue = sel. options [nIndex]. value;
Var sHTML = sel. options [nIndex]. innerHTML;
Sel. options [nIndex]. value = sel. options [nIndex-1]. value;
Sel. options [nIndex]. innerHTML = sel. options [nIndex-1]. innerHTML;
Sel. options [nIndex-1]. value = sValue;
Sel. options [nIndex-1]. innerHTML = sHTML;
Sel. selectedIndex = nIndex-1;
}
// Sort: Move down
Function Down ()
...{
Var sel = document. getElementById ("selectCheck ");
Var nIndex = sel. selectedIndex;
Var nLen = sel. length;
If (nLen <1) | (nIndex = nLen-1) return;
If (nIndex <0)
...{
Alert ("select a selected button to move! ");
Return;
}
Var sValue = sel. options [nIndex]. value;
Var sHTML = sel. options [nIndex]. innerHTML;
Sel. options [nIndex]. value = sel. options [nIndex + 1]. value;
Sel. options [nIndex]. innerHTML = sel. options [nIndex + 1]. innerHTML;
Sel. options [nIndex + 1]. value = sValue;
Sel. options [nIndex + 1]. innerHTML = sHTML;
Sel. selectedIndex = nIndex + 1;
}
// Move to the top
Function UpFirst ()
...{
Var sel = document. getElementById ("selectCheck ");
Var nIndex = sel. selectedIndex;
Var nLen = sel. options. length;
If (nLen <1) | (nIndex = 0) return;
If (nIndex <0)
...{
Alert ("select a selected button to move! ");
Return;
}
Var tempValue = document. getElementById ("tempValue"); // used to temporarily store the option value
TempValue. value = "";
For (var k = 0; k ...{
TempValue. value + = sel. options [k]. value + ";";
}
Var arrValue = tempValue. value. split (';');
Var sValue = sel. options [nIndex]. value;
Var sHTML = sel. options [nIndex]. innerHTML;
Sel. options [0]. value = sValue;
Sel. options [0]. innerHTML = sHTML;
For (var j = 1; j <= nIndex; j ++)
...{
Sel. options [j]. value = arrValue [J-1];
Sel. options [j]. innerHTML = arrValue [J-1];
}
Sel. selectedIndex = 0;
}
// Move to the end
Function DownLast ()
...{
Var sel = document. getElementById ("selectCheck ");
Var nIndex = sel. selectedIndex;
Var nLen = sel. options. length;
If (nLen <1) | (nIndex = nLen) return;
If (nIndex <0)
...{
Alert ("select a selected button to move! ");
Return;
}
Var tempValue = document. getElementById ("tempValue"); // used to temporarily store the option value
TempValue. value = "";
For (var k = nIndex + 1; k ...{
TempValue. value + = sel. options [k]. text + ";";
}
Var arrValue = tempValue. value. split (';');
Var sValue = sel. options [nIndex]. value;
Var sHTML = sel. options [nIndex]. innerHTML;
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service