鼠标选择动态改变网页背景颜色的JS代码_javascript技巧
程序员文章站
2022-04-04 10:58:15
...
采用Javascript实现,用鼠标点击相应颜色,动态改变网页背景颜色
var hex = new Array(6)')
document.write('')
document.write('')
document.write('')
document.write(' ')
}
function drawRow(red, blue) {
document.write('')
for (var i = 0; i drawCell(red, hex[i], blue)
}
document.write(' ')
}
function drawTable(blue) {
document.write('')
')
}
function drawCube() {
document.write('
')
}
drawCube()
这是截图
相应的Javascript源代码为:
复制代码 代码如下:
var hex = new Array(6)
hex[0] = "FF"
hex[1] = "CC"
hex[2] = "99"
hex[3] = "66"
hex[4] = "33"
hex[5] = "00"
function display(triplet) {
document.bgColor = '#' + triplet
}
function drawCell(red, green, blue) {
document.write('
document.write('')
document.write('')
document.write('')
document.write('
}
function drawRow(red, blue) {
document.write('
for (var i = 0; i drawCell(red, hex[i], blue)
}
document.write('
}
function drawTable(blue) {
document.write('
}
function drawCube() {
document.write('
') drawTable(hex[i]) document.write(' | ')
}
drawCube()
推荐阅读