特卖上下左右最终版

数组 inputField 已经封装了所有的text和checkbox的关键字;所以不用再去写一个数组来存放关键字,这样一劳永逸的解决了问题

 

function getFieldArryNum(fieldNm,type,obj){
    var returnObj = new Object();
    var next = null;
    var id = "";
    var row = obj.parentNode.parentNode.parentNode.rowIndex;
 for(var i=0;i<inputField.length;i++){
  if(fieldNm == inputField[i]){
     returnObj.number = i;
     if(type == "1"){
        if(i == 0){
          returnObj.nextFieldNm = inputField[(inputField.length)-1];
          id = pduList[row-2].pduID;
        }else{
          returnObj.nextFieldNm = inputField[i -1];
          id = pduList[row-1].pduID;
        }
         next= document.getElementById(returnObj.nextFieldNm + "_" + id);
      if(!next.disabled){
                next.focus();
              break;  
   }else{
     var nextIndex = returnObj.number - 2;
     while (nextIndex--){
         if(!document.getElementById(inputField[nextIndex] + "_" + id).disabled){
            document.getElementById(inputField[nextIndex] + "_" + id).focus();
            break;
         }
     }
   } 
     }else if(type == "2"){
        if(i == inputField.length -1){
          returnObj.nextFieldNm = inputField[0];
          id = pduList[row].pduID;
        }else{
          returnObj.nextFieldNm = inputField[i + 1];
          id = pduList[row-1].pduID;
        }
        next= document.getElementById(returnObj.nextFieldNm + "_" + id);
        if(!next.disabled){
                next.focus();
              break;  
   }else{
     var nextIndex = returnObj.number+1;
    // alert(nextIndex);
     while (nextIndex++){
         if(!document.getElementById(inputField[nextIndex] + "_" + id).disabled){
            document.getElementById(inputField[nextIndex] + "_" + id).focus();
            break;
         }
     }
   } 
       
       
     }else{
        returnObj.nextFieldNm = fieldNm;
     }
   
   
  }
  
  
    
 }
 //alert(returnObj);
 
}

function okd(obj,fieldNm){

var code_value =event.keyCode;
//var arr=new Array("MEMBER_PRICE","PRODUCT_UNIT","DESCRIPTION_20");
var arr = inputField;
var row = obj.parentNode.parentNode.parentNode.rowIndex;
var cellIndex = obj.parentNode.parentNode.cellIndex;

//左移
if(code_value==37){
      
  if(!(row==1&&fieldNm==arr[0])){
   getFieldArryNum(fieldNm,1,obj);
  }
 }
//右移
if(code_value==39){
    if(!((row==obj.parentNode.parentNode.parentNode.parentNode.rows.length-1)&&fieldNm==arr[arr.length-1])){
           getFieldArryNum(fieldNm,2,obj);
}
 }

//上移
if(code_value==38){
   // 当前行号
   if(row != 1){
     var row2 = obj.parentNode.parentNode.parentNode.rowIndex-2;
        // get id
     var id = pduList[row2].pduID;
     document.getElementById(fieldNm + "_" + id).focus();
 
}
}
//下移
if(code_value==40){
   // 当前行号
   if(row != obj.parentNode.parentNode.parentNode.parentNode.rows.length-1){
     var row2 = row-1+1;
        // get id
     var id = pduList[row2].pduID;
     document.getElementById(fieldNm + "_" + id).focus();
}
}
}

你可能感兴趣的:(特卖上下左右最终版)