# GÓC SÁNG TẠO > Khu vực lập trình > .NET >  Cách đổi màu trang web http://it.dlu.edu.vn

## sanxuattudien

Em thấy trang này có phần đổi màu, góc trên, anh chị nào biết cách làm chỉ em với, em gà lắm.

----------


## Diemasp1

Bạn nhúng vào một đoạn javascript styleswitcher.js như sau :


```

[COLOR=#000000][/COLOR][COLOR=#007700]function [/COLOR][COLOR=#0000BB]setActiveStyleSheet[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]title[/COLOR][COLOR=#007700]) {  var [/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]a[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]main[/COLOR][COLOR=#007700];  for([/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#0000BB]0[/COLOR][COLOR=#007700]; ([/COLOR][COLOR=#0000BB]a [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]document[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]getElementsByTagName[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"link"[/COLOR][COLOR=#007700])[[/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]]); [/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]++) {    if([/COLOR][COLOR=#0000BB]a[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]getAttribute[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"rel"[/COLOR][COLOR=#007700]).[/COLOR][COLOR=#0000BB]indexOf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"style"[/COLOR][COLOR=#007700]) != -[/COLOR][COLOR=#0000BB]1 [/COLOR][COLOR=#007700]&& [/COLOR][COLOR=#0000BB]a[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]getAttribute[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"title"[/COLOR][COLOR=#007700])) {      [/COLOR][COLOR=#0000BB]a[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]disabled [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]true[/COLOR][COLOR=#007700];      if([/COLOR][COLOR=#0000BB]a[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]getAttribute[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"title"[/COLOR][COLOR=#007700]) == [/COLOR][COLOR=#0000BB]title[/COLOR][COLOR=#007700]) [/COLOR][COLOR=#0000BB]a[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]disabled [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]false[/COLOR][COLOR=#007700];    }  }}function [/COLOR][COLOR=#0000BB]getActiveStyleSheet[/COLOR][COLOR=#007700]() {  var [/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]a[/COLOR][COLOR=#007700];  for([/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#0000BB]0[/COLOR][COLOR=#007700]; ([/COLOR][COLOR=#0000BB]a [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]document[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]getElementsByTagName[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"link"[/COLOR][COLOR=#007700])[[/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]]); [/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]++) {    if([/COLOR][COLOR=#0000BB]a[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]getAttribute[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"rel"[/COLOR][COLOR=#007700]).[/COLOR][COLOR=#0000BB]indexOf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"style"[/COLOR][COLOR=#007700]) != -[/COLOR][COLOR=#0000BB]1 [/COLOR][COLOR=#007700]&& [/COLOR][COLOR=#0000BB]a[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]getAttribute[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"title"[/COLOR][COLOR=#007700]) && ![/COLOR][COLOR=#0000BB]a[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]disabled[/COLOR][COLOR=#007700]) return [/COLOR][COLOR=#0000BB]a[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]getAttribute[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"title"[/COLOR][COLOR=#007700]);  }  return [/COLOR][COLOR=#0000BB]null[/COLOR][COLOR=#007700];}function [/COLOR][COLOR=#0000BB]getPreferredStyleSheet[/COLOR][COLOR=#007700]() {  var [/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]a[/COLOR][COLOR=#007700];  for([/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#0000BB]0[/COLOR][COLOR=#007700]; ([/COLOR][COLOR=#0000BB]a [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]document[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]getElementsByTagName[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"link"[/COLOR][COLOR=#007700])[[/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]]); [/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]++) {    if([/COLOR][COLOR=#0000BB]a[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]getAttribute[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"rel"[/COLOR][COLOR=#007700]).[/COLOR][COLOR=#0000BB]indexOf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"style"[/COLOR][COLOR=#007700]) != -[/COLOR][COLOR=#0000BB]1       [/COLOR][COLOR=#007700]&& [/COLOR][COLOR=#0000BB]a[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]getAttribute[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"rel"[/COLOR][COLOR=#007700]).[/COLOR][COLOR=#0000BB]indexOf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"alt"[/COLOR][COLOR=#007700]) == -[/COLOR][COLOR=#0000BB]1       [/COLOR][COLOR=#007700]&& [/COLOR][COLOR=#0000BB]a[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]getAttribute[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"title"[/COLOR][COLOR=#007700])       ) return [/COLOR][COLOR=#0000BB]a[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]getAttribute[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"title"[/COLOR][COLOR=#007700]);  }  return [/COLOR][COLOR=#0000BB]null[/COLOR][COLOR=#007700];}function [/COLOR][COLOR=#0000BB]createCookie[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]name[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000BB]value[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000BB]days[/COLOR][COLOR=#007700]) {  if ([/COLOR][COLOR=#0000BB]days[/COLOR][COLOR=#007700]) {    var [/COLOR][COLOR=#0000BB]date [/COLOR][COLOR=#007700]= new [/COLOR][COLOR=#0000BB]Date[/COLOR][COLOR=#007700]();    [/COLOR][COLOR=#0000BB]date[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]setTime[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]date[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]getTime[/COLOR][COLOR=#007700]()+([/COLOR][COLOR=#0000BB]days[/COLOR][COLOR=#007700]*[/COLOR][COLOR=#0000BB]24[/COLOR][COLOR=#007700]*[/COLOR][COLOR=#0000BB]60[/COLOR][COLOR=#007700]*[/COLOR][COLOR=#0000BB]60[/COLOR][COLOR=#007700]*[/COLOR][COLOR=#0000BB]1000[/COLOR][COLOR=#007700]));    var [/COLOR][COLOR=#0000BB]expires [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#DD0000]"; expires="[/COLOR][COLOR=#007700]+[/COLOR][COLOR=#0000BB]date[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]toGMTString[/COLOR][COLOR=#007700]();  }  else [/COLOR][COLOR=#0000BB]expires [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#DD0000]""[/COLOR][COLOR=#007700];  [/COLOR][COLOR=#0000BB]document[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]cookie [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]name[/COLOR][COLOR=#007700]+[/COLOR][COLOR=#DD0000]"="[/COLOR][COLOR=#007700]+[/COLOR][COLOR=#0000BB]value[/COLOR][COLOR=#007700]+[/COLOR][COLOR=#0000BB]expires[/COLOR][COLOR=#007700]+[/COLOR][COLOR=#DD0000]"; path=/"[/COLOR][COLOR=#007700];}function [/COLOR][COLOR=#0000BB]readCookie[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]name[/COLOR][COLOR=#007700]) {  var [/COLOR][COLOR=#0000BB]nameEQ [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]name [/COLOR][COLOR=#007700]+ [/COLOR][COLOR=#DD0000]"="[/COLOR][COLOR=#007700];  var [/COLOR][COLOR=#0000BB]ca [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]document[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]cookie[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]split[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]';'[/COLOR][COLOR=#007700]);  for(var [/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#0000BB]0[/COLOR][COLOR=#007700];[/COLOR][COLOR=#0000BB]i [/COLOR][COLOR=#007700]< [/COLOR][COLOR=#0000BB]ca[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]length[/COLOR][COLOR=#007700];[/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]++) {    var [/COLOR][COLOR=#0000BB]c [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]ca[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000BB]i[/COLOR][COLOR=#007700]];    while ([/COLOR][COLOR=#0000BB]c[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]charAt[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]0[/COLOR][COLOR=#007700])==[/COLOR][COLOR=#DD0000]' '[/COLOR][COLOR=#007700]) [/COLOR][COLOR=#0000BB]c [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]c[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]substring[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]1[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000BB]c[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]length[/COLOR][COLOR=#007700]);    if ([/COLOR][COLOR=#0000BB]c[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]indexOf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]nameEQ[/COLOR][COLOR=#007700]) == [/COLOR][COLOR=#0000BB]0[/COLOR][COLOR=#007700]) return [/COLOR][COLOR=#0000BB]c[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]substring[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]nameEQ[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]length[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000BB]c[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]length[/COLOR][COLOR=#007700]);  }  return [/COLOR][COLOR=#0000BB]null[/COLOR][COLOR=#007700];}[/COLOR][COLOR=#0000BB]window[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]onload [/COLOR][COLOR=#007700]= function([/COLOR][COLOR=#0000BB]e[/COLOR][COLOR=#007700]) {  var [/COLOR][COLOR=#0000BB]cookie [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]readCookie[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"style"[/COLOR][COLOR=#007700]);  var [/COLOR][COLOR=#0000BB]title [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]cookie [/COLOR][COLOR=#007700]? [/COLOR][COLOR=#0000BB]cookie [/COLOR][COLOR=#007700]: [/COLOR][COLOR=#0000BB]getPreferredStyleSheet[/COLOR][COLOR=#007700]();  [/COLOR][COLOR=#0000BB]setActiveStyleSheet[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]title[/COLOR][COLOR=#007700]);}[/COLOR][COLOR=#0000BB]window[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]onunload [/COLOR][COLOR=#007700]= function([/COLOR][COLOR=#0000BB]e[/COLOR][COLOR=#007700]) {  var [/COLOR][COLOR=#0000BB]title [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]getActiveStyleSheet[/COLOR][COLOR=#007700]();  [/COLOR][COLOR=#0000BB]createCookie[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"style"[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]title[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]365[/COLOR][COLOR=#007700]);}var [/COLOR][COLOR=#0000BB]cookie [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]readCookie[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"style"[/COLOR][COLOR=#007700]);var [/COLOR][COLOR=#0000BB]title [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]cookie [/COLOR][COLOR=#007700]? [/COLOR][COLOR=#0000BB]cookie [/COLOR][COLOR=#007700]: [/COLOR][COLOR=#0000BB]getPreferredStyleSheet[/COLOR][COLOR=#007700]();[/COLOR][COLOR=#0000BB]setActiveStyleSheet[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]title[/COLOR][COLOR=#007700]);[/COLOR] 


```

sau đó ở trang ban muốn đổi màu chỉ cần gọi nó ... tương tự như thế này :


```

[COLOR=#000000][/COLOR][COLOR=#007700]<[/COLOR][COLOR=#0000BB]script type[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]"text/javascript" [/COLOR][COLOR=#0000BB]src[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#DD0000]"styleswitcher.js"[/COLOR][COLOR=#007700]>function [/COLOR][COLOR=#0000BB]IMG1_onclick[/COLOR][COLOR=#007700]() {}[/COLOR] 


```

PS : đã rất lâu rồi tớ mới quay trở lại diễn đàn nó vẩn như xưa.... có điều ngày càng có nhiều câu hỏi xin code...#-o

----------

