站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Javascript 专题手动排序(javascript)

手动排序(javascript)

摘要: 手动排序(javascript)
<textarea readonly style="border:none;font-family:Courier New;line-height:150%;width:760px;overflow-y:visible">
<table width=200 align=center border=0> <tr> <td class=Title noWrap align=middle>手工排序 </td></tr></table>
<form id=Form1 action=do.asp method=post> <table align=center> <tr align=middle> <td width=160><select style="WIDTH: 120px" size=10 name=list1> <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 onclick=add() type=button value="增 加>>>">

<input onclick=del() type=button value="<<<删 除"> </td> <td width=79><select id=seqItem style="WIDTH: 120px" size=10 name=seqItem></select></td> <td width=79>

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

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

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

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

</td></tr></table> <input onclick=goClick() type=button value="测 试"> <input onclick=doRe() type=button value="重 置"> <input type=submit value="提 交" name=ok>
---------------------------------------------------------------------------------------------
HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<head>
start
<link> rel="stylesheet" href="../../css/main.css" type="text/css">
</head>
<body MS_POSITIONING="GridLayout">



<table width="200" border="0" align="center">
<tr>
<td class="Title" align="center" nowrap>
手工排序
</td>
</tr>
</table>


<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()">




<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>


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



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



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



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

</td>
</tr>
</table>

<input type="button" value="测 试" onClick="goClick()">
<input type="button" value="重 置" onClick="doRe()">
<input type="submit" name="ok" value="提 交">

</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 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 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 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 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 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 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 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{
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>
</form> 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;ii){ 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=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