行,列換色處理 列頭 列頭 列頭 列頭 sdfsdfsdfsdfsd sdfsdfds sdfsd sdfsdfsd 22222 33333 232323 23232 <br>//table_tr_td_color.js <br>//让表的tr和td进行换色 <br>//在页面最下面执行:Init_Table_Tr_Td("Permit_View_Talbe"); <br>//需要换色的行代码:Chang_Tr_over(this,document.all.表id,1)为换色 Chang_Tr_over(this,document.all.表id,0)为恢复原色 <br>//例: <tr onMouseOver="Chang_Tr_over(this,document.all.Permit_View_Talbe,1)" onMouseOut="Chang_Tr_over(this,document.all.Permit_View_Talbe,0)"> <br>//需要换色的列代码:Change_TdBgColor(this,document.all.表id) <br>//注:行和列的背景色在默認的情況下請用bgcolor和background來定義 <br>//根据需要,可以调整代码里的值是否 for循环里的条件值 -1 <br>//最好是用background <br>//設置列的換色------------------------ <br><br>var Td_BackGround_Color_Array = Array(); <br>var Td_Font_Color_Array = Array(); <br>//選中後RD的顏色和字體的顏色 <br>var Change_BackGround_color ="#4684c1"; <br>var Change_Font_color ="#ffffff"; <br>//下面兩色為原始的背景色和原始字的顏色 <br>var Old_BackGround_Color = "#ffffff"; <br>var Old_Font_color = "#000000"; <br>//-------------------------------------- <br>//設置行的換色 <br>var Tr_Change_BackGround="#72a3cf"; <br>var Tr_Change_Fontcolor="#ffffff"; <br><br>var Cell_Selected_Array = Array(); <br><br>function Init_Table_Tr_Td(Table_id){ <br> var Table_Object = document.all.item(Table_id); <br> var Table_Tr_Length = parseInt(Table_Object.rows.length); <br> var Table_Td_Length = parseInt(Table_Object.rows[1].cells.length); <br><br> //初始化記錄表格中的每一個RD的背景色和字體顏色 <br> for(var i=0;i<Table_Tr_Length;i++){ <BR> Td_BackGround_Color_Array[i] = Array(); <BR> Td_Font_Color_Array[i] = Array(); <br><br> for(var y=0;y<Table_Td_Length;y++){ <BR> //如果初始情況下沒有進行設置style.backgrund的話,則默認為上面設置的原始色 <BR> if(!Table_Object.rows[i].cells[y].style.Background){ <BR> if(Table_Object.rows[i].style.Background){ <BR> Table_Object.rows[i].cells[y ].style.Background=Table_Object.rows[i].style.Background; <BR> }else{ <BR> if(Table_Object.rows[i].bgColor){ <BR> Table_Object.rows[i].bgColor; <BR> }else{ <BR> if(Table_Object.rows[i].cells[y].bgColor) <BR> Table_Object.rows[i].cells[y].style.Background=Table_Object.rows[i] .cells[y].bgColor; <BR> else <BR> Table_Object.rows[i].cells[y].style.Background=Old_BackGround_Color;//否則為設置的底color <BR> } <BR> } <BR> } <BR> //如果初始情況下沒有進行設置style.color的話,則默認為上face設置的原始color <BR> if(!Table_Object.rows[i].cells[y].style.color){ if(!Table_Object .rows[i].style.color){ <BR> Table_Object.rows[i].cells[y].style.color =Old_Font_color; <BR> }else{ <BR> Table_Object.rows[i].cells[y].style.color =Table_Object.rows[i].style.color; <BR> } <BR> } <BR><br> Td_BackGround_Color_Array[i][y] = Table_Object.rows[i].cells[y].style.ground; <br> Td_Font_Color_Array[i][y] = Table_Object.rows[i].cells[y].style.color; <BR> }// END FOR Y <BR> }// END FOR I <BR>} <BR><br>//設置列的顏color <br>함수 Change_TdBgColor(me,Table_Object){ <BR> var t d객체 = 나; <BR> while(tdobject.tagName!="TD"){tdobject = tdobject.parentElement;}<BR> var tdindex = tdobject.cellIndex; <BR> var Table_Tr_Length = parseInt(Table_Object.rows.length); <BR> var Table_Td_Length = parseInt(Table_Object.rows[0].cells.length); <br><br> for(var i=1;i<Table_Tr_Length;i ){ <BR> if(Table_Object.rows[i].cells[tdindex].style.Background==Td_BackGround_Color_Array[i][tdindex]) { <BR> Table_Object.rows[i].cells[tdindex].style.Background=Change_BackGround_color; <BR> Table_Object.rows[i].cells[tdindex].style.color=Change_Font_color; <BR> Cell_Selected_Array.push(tdindex); <BR> }else{ <BR> Table_Object.rows[i].cells[tdindex].style.Background=Td_BackGround_Color_Array[i][tdindex]; <BR> Table_Object.rows[i].cells[tdindex].style.color=Td_Font_Color_Array[i][tdindex]; <BR> for(var c=0;c<Cell_Selected_Array.length;c ){ <BR> if(Cell_Selected_Array[c] == tdindex) Cell_Selected_Array.splice(c,1); <BR> } <BR> } <BR> } <BR>} <BR>//設置行的顏color <BR>function Chang_Tr_over(me,Table_object,flag){ <BR> var trobject = me; <BR> while(trobject.tagName!="TR"){trobject = trobject.parentElement;} <BR> var trindex = trobject.rowIndex; <BR> var Table_Tr_Length = parseInt(Table_object.rows.length); <BR> var Table_Td_Length = parseInt(Table_object.rows[trindex].cells.length); <br><br> var flag_td ="," Cell_Selected_Array ","; <BR> for(var i=0;i<Table_Td_Length;i ){ <BR> var value = "," i ","; <BR> if(flag_td.indexOf(value)!=-1) 계속; <BR> if(flag==1){ <BR> Table_object.rows[trindex].cells[i].style.Background=Tr_Change_BackGround; <BR> Table_object.rows[trindex].cells[i].style.color=Tr_Change_Fontcolor; <BR> }else{ <BR> Table_object.rows[trindex].cells[i].style.Background=Td_BackGround_Color_Array[trindex][i]; <BR> Table_object.rows[trindex].cells[i].style.color=Td_Font_Color_Array[trindex][i]; <BR> } <BR> } <br><br>} <br><br>Init_Table_Tr_Td("Permit_View_Talbe"); <BR>