javascript问题 拖动表单
获得对象的名字sort[0].name好像没有改变,第二次拖动的时候改变所获取的对象是未改变前的
我希望得到的是:每次拖动表格后,sort都是1,2,3,4,5
<HTML>
<HEAD>
<title> change table sort </title>
<script language= "Javascript ">
var beginMoving=false;
function MouseDownToMove(obj){
obj.style.zIndex=1;
obj.mouseDownY=event.clientY;
obj.mouseDownX=event.clientX;
beginMoving=true;
obj.setCapture();
}
function MouseMoveToMove(obj){
if(!beginMoving) return false;
obj.style.top = (event.clientY-obj.mouseDownY);
obj.style.left = (event.clientX-obj.mouseDownX);
}
function MouseUpToMove(obj){
if(!beginMoving) return false;
obj.releaseCapture();
obj.style.top=0;
obj.style.left=0;
obj.style.zIndex=0;
beginMoving=false;
var tempTop=event.clientY-obj.mouseDownY;
var tempRowIndex=(tempTop-tempTop%25)/25;
if(tempRowIndex+obj.rowIndex <0 ){
tempRowIndex=-1;
}
else tempRowIndex=tempRowIndex+obj.rowIndex;
if(tempRowIndex > = obj.parentElement.rows.length-1){
tempRowIndex = obj.parentElement.rows.length-1;
}
alert( "1: "+obj.rowIndex+ "--> "+tempRowIndex);
var a = obj.rowIndex;
var b = tempRowIndex;
obj.parentElement.moveRow(obj.rowIndex,tempRowIndex);
alert( "start。。。 ");
//move to down
if(a <b){
var j = a+1;
var k = b+1;
var temp= "he ";
var sort_temp = document.getElementsByName(a+ "_sort ");
sort_temp[0].value = temp;
sort_temp[0].name = temp+ "_sort ";
for(var i=j;i <k;i++){
var sort = document.getElementsByName(i+ "_sort ");
var tempValue = sort[0].value-1;
sort[0].value = tempValue;
sort[0].name = tempValue+ "_sort ";
alert(sort[0].name);
}
sort_temp[0].value = b;
sort_temp[0].name = b+ "_sort ";
alert(sort_temp[0].name+ "= "+sort_temp[0].value);
}
//move to up
else{
var j = a;
var k = b;
var temp= "he ";
var sort_temp = document.getElementsByName(a+ "_sort ");
sort_temp[0].value = temp;
sort_temp[0].name = temp+ "_sort ";
for(var i=b;i <j;i++){
var sort = document.getElementsByName(i+ "_sort ");
var tempValue = parseFloat(sort[0].value)+parseFloat(1);
sort[0].value = tempValue;
sort[0].name = tempValue+ "_sort ";
}
sort_temp[0].value = b;
sort_temp[0].name = b+ "_sort ";
}
alert( "end! ");
}
</script>
</HEAD>
<body>
<form>
<div style= "width:650px;height:500px;overflow-y:scroll; ">
<table width= "600 " border= "1 " cellpadding= "2 " cellspacing= "0 " class= 'lms_table ' >
<tr>
<th align= "center " height= "22 " > sort </th>
<th align= "center " height= "22 " > title </th>
</tr>
<tr style= 'position:relative; ' onmousedown= 'MouseDownToMove(this) ' onmousemove= 'MouseMoveToMove(this) ' onmouseup= 'MouseUpToMove(this); '>
<td> <input name= '1_sort ' type= 'text ' value= '1 ' > </td>
<td> <input name= '1_title ' type= 'text ' value= '1_sort_a ' > </td>
</tr>
<tr style= 'position:relative; ' onmousedown= 'MouseDownToMove(this) ' onmousemove= 'MouseMoveToMove(this) ' onmouseup= 'MouseUpToMove(this); '>
<td> <input name= '2_sort ' type= 'text ' value= '2 ' > </td>
<td> <input name= '2_title ' type= 'text ' value= '2_sort_b ' > </td>
</tr>
<tr style= 'position:relative; ' onmousedown= 'MouseDownToMove(this) ' onmousemove= 'MouseMoveToMove(this) ' onmouseup= 'MouseUpToMove(this); '>
<td> <input name= '3_sort ' type= 'text ' value= '3 ' > </td>
<td> <input name= '3_title ' type= 'text ' value= '3_sort_c ' > </td>
</tr>
<tr style= 'position:relative; ' onmousedown= 'MouseDownToMove(this) ' onmousemove= 'MouseMoveToMove(this) ' onmouseup= 'MouseUpToMove(this); '>
<td> <input name= '4_sort ' type= 'text ' value= '4 ' > </td>
<td> <input name= '4_title ' type= 'text ' value= '4_sort_d ' > </td>
</tr>
<tr style= 'position:relative; ' onmousedown= 'MouseDownToMove(this) ' onmousemove= 'MouseMoveToMove(this) ' onmouseup= 'MouseUpToMove(this); '>
<td> <input name= '5_sort ' type= 'text ' value= '5 ' > </td>
<td> <input name= '5_title ' type= 'text ' value= '5_sort_e ' > </td>
</tr>
</table>
</div>
</form>
</body>
</html>
[解决办法]
都没人理我,哇哇哇....
人家第一次问诶