通用的javascript 换行色换列色的小js




行,列�Q色�理




   
    列�^
    列�^
    列�^
    列�^
  
  
    sdfsdfsdfsdfsd
    sdfsdfds
    sdfsd
    sdfsdfsd
  
  
     
     
     
     
  
  
     
     
     
     
  
  
     
     
     
     
  
  
     
     
     
     
  
  
     
     
     
     
  
  
     
     
     
     
  
  
    22222
    33333
    232323
    23232
  
  
     
     
     
     
  
  
     
     
     
     
  
  
     
     
     
     
  
  
     
     
     
     
  
  
     
     
     
     
  
  
     
     
     
     
  
  
     
     
     
     
  
  
     
     
     
     
  
  
     
     
     
     
  
  
     
     
     
     
  
  
     
     
     
     
  
  
     
     
     
     
  
  
     
     
     
     
  




//table_tr_td_color.js
//让表的tr和td进行换色
//在页面最下面执行:Init_Table_Tr_Td("Permit_View_Talbe");
//需要换色的行代码:Chang_Tr_over(this,document.all.表id,1)为换色 Chang_Tr_over(this,document.all.表id,0)为恢复原色
//例:    
//需要换色的列代码:Change_TdBgColor(this,document.all.表id)
//注:行和列的背景色在默�J的情�r下�用bgcolor和background�矶��x
//根据需要,可以调整代码里的值是否    for循环里的条件值    -1
//最好是用background
//�O置列的�Q色------------------------

var Td_BackGround_Color_Array    = Array();
var Td_Font_Color_Array         = Array();
//�x中後RD的�色和字�w的�色
var Change_BackGround_color ="#4684c1";
var Change_Font_color        ="#ffffff";
//下面�缮��樵�始的背景色和原始字的�色    
var Old_BackGround_Color    = "#ffffff";
var Old_Font_color            = "#000000";
//--------------------------------------
//�O置行的�Q色
var Tr_Change_BackGround="#72a3cf";
var Tr_Change_Fontcolor="#ffffff";

var Cell_Selected_Array = Array();

function Init_Table_Tr_Td(Table_id){
    var Table_Object = document.all.item(Table_id);
    var Table_Tr_Length = parseInt(Table_Object.rows.length);
    var Table_Td_Length = parseInt(Table_Object.rows[1].cells.length);

    //初始化��表格中的每一��RD的背景色和字�w�色    
    for(var i=0;i        Td_BackGround_Color_Array[i] = Array();
        Td_Font_Color_Array[i] = Array();

        for(var y=0;y            //如果初始情�r下�]有�M行�O置style.backgrund的�,�t默�J�樯厦嬖O置的原始色
            if(!Table_Object.rows[i].cells[y].style.background){    
                if(Table_Object.rows[i].style.background){
                    Table_Object.rows[i].cells[y].style.background=Table_Object.rows[i].style.background;
                }else{
                    if(Table_Object.rows[i].bgColor){
                            Table_Object.rows[i].cells[y].style.background=Table_Object.rows[i].bgColor;
                    }else{                
                        if(Table_Object.rows[i].cells[y].bgColor)
                            Table_Object.rows[i].cells[y].style.background=Table_Object.rows[i].cells[y].bgColor;
                        else
                            Table_Object.rows[i].cells[y].style.background=Old_BackGround_Color;//否�t�樵O置的底色
                    }
                }
            }
            //如果初始情�r下�]有�M行�O置style.color的�,�t默�J�樯厦嬖O置的原始色
            if(!Table_Object.rows[i].cells[y].style.color){
                if(!Table_Object.rows[i].style.color){
                    Table_Object.rows[i].cells[y].style.color    =Old_Font_color;
                }else{
                    Table_Object.rows[i].cells[y].style.color    =Table_Object.rows[i].style.color;
                }
            }

            Td_BackGround_Color_Array[i][y] = Table_Object.rows[i].cells[y].style.background;
            Td_Font_Color_Array[i][y] = Table_Object.rows[i].cells[y].style.color;
        }// END FOR Y    
    }// END FOR I    
}

//�O置列的�色
function Change_TdBgColor(me,Table_Object){
    var tdobject = me;
    while(tdobject.tagName!="TD"){tdobject = tdobject.parentElement;}
    var tdindex = tdobject.cellIndex;
    var Table_Tr_Length = parseInt(Table_Object.rows.length);
    var Table_Td_Length = parseInt(Table_Object.rows[0].cells.length);

    for(var i=1;i        if(Table_Object.rows[i].cells[tdindex].style.background==Td_BackGround_Color_Array[i][tdindex]){
            Table_Object.rows[i].cells[tdindex].style.background=Change_BackGround_color;
            Table_Object.rows[i].cells[tdindex].style.color=Change_Font_color;
            Cell_Selected_Array.push(tdindex);
        }else{
            Table_Object.rows[i].cells[tdindex].style.background=Td_BackGround_Color_Array[i][tdindex];
            Table_Object.rows[i].cells[tdindex].style.color=Td_Font_Color_Array[i][tdindex];
            for(var c=0;c                if(Cell_Selected_Array[c] == tdindex) Cell_Selected_Array.splice(c,1);
            }
        }
    }    
}
//�O置行的�色
function Chang_Tr_over(me,Table_object,flag){
    var trobject = me;
    while(trobject.tagName!="TR"){trobject = trobject.parentElement;}
    var trindex = trobject.rowIndex;
    var Table_Tr_Length = parseInt(Table_object.rows.length);
    var Table_Td_Length = parseInt(Table_object.rows[trindex].cells.length);

    var flag_td =","+Cell_Selected_Array+","; 
    for(var i=0;i        var value = ","+i+",";
        if(flag_td.indexOf(value)!=-1) continue;
        if(flag==1){
            Table_object.rows[trindex].cells[i].style.background=Tr_Change_BackGround;
            Table_object.rows[trindex].cells[i].style.color=Tr_Change_Fontcolor;
        }else{
            Table_object.rows[trindex].cells[i].style.background=Td_BackGround_Color_Array[trindex][i];
            Table_object.rows[trindex].cells[i].style.color=Td_Font_Color_Array[trindex][i];
        }
    }

}

Init_Table_Tr_Td("Permit_View_Talbe");

行,列�Q色�理
列�^ 列�^ 列�^ 列�^
sdfsdfsdfsdfsd sdfsdfds sdfsd sdfsdfsd
       
       
       
       
       
       
22222 33333 232323 23232
       
       
       
       
       
       
       
       
       
       
       
       
       

[Ctrl+A 全选 注: 如需引入外部Js需刷新才能执行]

你可能感兴趣的:(通用的javascript 换行色换列色的小js)