Javascript技巧实例精选(1)—鼠标选择动态改变网页背景颜色

 

>>点击这里下载html源文件代码<<

采用Javascript实现,用鼠标点击相应颜色,动态改变网页背景颜色

这是截图

Javascript技巧实例精选(1)—鼠标选择动态改变网页背景颜色

相应的Javascript源代码为:

 1 var hex = new Array(6)

 2 

 3 hex[0] = "FF"

 4 hex[1] = "CC"

 5 hex[2] = "99"

 6 hex[3] = "66"

 7 hex[4] = "33"

 8 hex[5] = "00"

 9 function display(triplet) {

10 document.bgColor = '#' + triplet

11 }

12 function drawCell(red, green, blue) {

13 document.write('<TD BGCOLOR="#' + red + green + blue + '">')

14 document.write('<A HREF="javascript:display(\'' + (red + green + blue) + '\')">')

15 document.write('<IMG SRC="place.gif" BORDER=0 HEIGHT=12 WIDTH=12>')

16 document.write('</A>')

17 document.write('</TD>')

18 }

19 function drawRow(red, blue) {

20 document.write('<TR>')

21 for (var i = 0; i < 6; ++i) {

22 drawCell(red, hex[i], blue)

23 }

24 document.write('</TR>')

25 }

26 function drawTable(blue) {

27 document.write('<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0>')

28 for (var i = 0; i < 6; ++i) {

29 drawRow(hex[i], blue)

30 }

31 document.write('</TABLE>')    

32 }

33 function drawCube() {

34 document.write('<TABLE CELLPADDING=5 CELLSPACING=0 BORDER=1><TR>')

35 for (var i = 0; i < 6; ++i) {

36 document.write('<TD BGCOLOR="#FFFFFF">')

37 drawTable(hex[i])

38 document.write('</TD>')

39 }

40 document.write('</TR></TABLE>')

41 }

42 drawCube()

 

你可能感兴趣的:(JavaScript)