当前位置: 代码迷 >> Java Web开发 >> javascript有关问题 拖动表单
  详细解决方案

javascript有关问题 拖动表单

热度:33   发布时间:2016-04-17 14:12:55.0
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;
  相关解决方案