手动排序(javascript)

王朝html/css/js·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

手工排序

1111111 2222222 3333333 4444444 5555555 6666666 7777777

"

---------------------------------------------------------------------------------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head>

<title>start</title>

<LINK rel="stylesheet" href="../../css/main.css" type="text/css">

<meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head>

<body MS_POSITIONING="GridLayout">

<FONT face="宋体"></FONT><FONT face="宋体"></FONT><FONT face="宋体"></FONT>

<BR>

<table width="200" border="0" align="center">

<tr>

<td class="Title" align="center" nowrap>

手工排序

</td>

</tr>

</table>

<BR>

<form id="Form1" method="post" action="do.asp">

<table align="center">

<tr align=center>

<td width=160><select size=10 name="list1" style="width:120">

<option value=1>1111111</option>

<option value=2>2222222</option>

<option value=3>3333333</option>

<option value=4>4444444</option>

<option value=5>5555555</option>

<option value=6>6666666</option>

<option value=7>7777777</option>

</select></td>

<td><input type="button" value="增 加>>>" onclick="add()">

<br/>

<br/>

<input type="button" value="<<<删 除" onclick="del()">

</td>

<td width=79><select name="seqItem" id="seqItem" size="10" style="width:120">

</select></td>

<td width=79><p align="center">

<input type="button" value="移动到顶部" onClick="doTopItem()">

</p>

<p align="center">

<input type="button" name="Submit" value="向上移动" onClick="doUpItem()">

</p>

<p align="center">

<input type="button" name="Submit" value="向下移动" onClick="doDownItem()" >

</p>

<p align="center">

<input type="button" name="Submit" value="移动到底部" onClick="doBottomItem()">

</p></td>

</tr>

</table>

<div align="center">

<input type="button" value="测 试" onClick="goClick()">

<input type="button" value="重 置" onClick="doRe()">

<input type="submit" name="ok" value="提 交">

</div>

</form>

<SCRIPT LANGUAGE="javascript">

var seqSelect=document.forms[0].seqItem;

var length=5;

//go top

function doTopItem(){

var length=seqSelect.options.length;

var topV,topT;

var tempV=new Array();

var tempT=new Array();

for(var i=0;i<length;i++){

if(seqSelect.options[i].selected){

if(i==0)

return false;

topV=seqSelect.options[0].value;

topT=seqSelect.options[0].text;

seqSelect.options[0].value=seqSelect.options[i].value;

seqSelect.options[0].text=seqSelect.options[i].text;

for(var j=1;j<length;j++){

tempV[j]=seqSelect.options[j].value;

tempT[j]=seqSelect.options[j].text;

alert(tempV+" ··· "+tempT);

if(j==1){

seqSelect.options[1].value=topV;

seqSelect.options[1].text=topT;

}

else if(j>i){

break;

}

else{

seqSelect.options[j].value=tempV[j-1];

seqSelect.options[j].text=tempT[j-1];

}

}

}

}

seqSelect.options[0].selected=true;

}

//go bottom

function doBottomItem(){

var length=seqSelect.options.length;

var bottomV,bottomT;

var tempV=new Array();

var tempT=new Array();

for(var i=0;i<length;i++){

if(seqSelect.options[i].selected){

if(i==(length-1))

return false;

bottomV=seqSelect.options[length-1].value;

bottomT=seqSelect.options[length-1].text;

seqSelect.options[length-1].value=seqSelect.options[i].value;

seqSelect.options[length-1].text=seqSelect.options[i].text;

for(var j=length-2;j>=0;j--){

tempV[j]=seqSelect.options[j].value;

tempT[j]=seqSelect.options[j].text;

alert(tempV+" ··· "+tempT);

if(j==(length-2)){

seqSelect.options[length-2].value=bottomV;

seqSelect.options[length-2].text=bottomT;

}

else if(j<i){

break;

}

else{

seqSelect.options[j].value=tempV[j+1];

seqSelect.options[j].text=tempT[j+1];

}

}

}

}

seqSelect.options[length-1].selected=true;

}

//go up 1

function doUpItem(){

var length=seqSelect.options.length;

var tempV,tempT;

for(var i=0;i<length;i++){

if(seqSelect.options[i].selected){

if(i==0)

return false;

tempV=seqSelect.options[i-1].value;

tempT=seqSelect.options[i-1].text;

seqSelect.options[i-1].value=seqSelect.options[i].value;

seqSelect.options[i-1].text=seqSelect.options[i].text;

seqSelect.options[i].value=tempV;

seqSelect.options[i].text=tempT;

seqSelect.options[i-1].selected=true;

break;

}

}

}

//go down 1

function doDownItem(){

var length=seqSelect.options.length;

var tempV,tempT;

for(var i=0;i<length;i++){

if(seqSelect.options[i].selected){

if(i==(length-1))

return false;

tempV=seqSelect.options[i+1].value;

tempT=seqSelect.options[i+1].text;

seqSelect.options[i+1].value=seqSelect.options[i].value;

seqSelect.options[i+1].text=seqSelect.options[i].text;

seqSelect.options[i].value=tempV;

seqSelect.options[i].text=tempT;

seqSelect.options[i+1].selected=true;

break;

}

}

}

function doRe(){

document.forms[0].action="";

document.forms[0].submit();

}

function setCursor(objStyle,cursor)

{

objStyle.cursor = cursor;

}

<!--

function goClick()

{

var res ="";

for (var i =0;i<seqSelect.options.length;i++)

{

if(seqSelect.options[i].selected)

{

res += seqSelect.options[i].index +",";

}

}

alert(res);

}

//-->

function add_singer(object,value,text)//添加数据

{

if(singer_exist(object,value)==false)

{

object.options.add(new Option(text,value,true,true));

return true;

}

return false;

}

function remove_singer(object,index)//删除数据

{

if(index<0)return false;

object.options.remove(index)

}

function singer_exist(object,value)//检查是否存在

{

for(var i=0;i<object.options.length; i++)

{

if(object.options[i].value==value)

return true;

}

return false;

}

function add()

{

var obj1=document.all.list1;

var index=obj1.selectedIndex;

if (index<0) return false;

value=obj1.options[index].value;

text=obj1.options[index].text;

var obj2=document.all.seqItem;

add_singer(obj2,value,text)

remove_singer(obj1,index)

}

function del()

{

var obj2=document.all.seqItem;

var index=obj2.selectedIndex;

if (index<0) return false;

value=obj2.options[index].value;

text=obj2.options[index].text;

var obj1=document.all.list1;

add_singer(obj1,value,text)

remove_singer(obj2,index)

}

</script>

</body>

</html>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航