html随机获取颜色代码,html肿么让字体得到随机颜色

!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd

html xmlns=http://www.w3.org/1999/xhtml

head

meta http-equiv=Content-Type content=text/html; charset=gb2312 /

title会变色的字/title

/head

body

div ba href = id = ppp会变色的字/a/b

a href = id = pp会变色的字/a

a href = id = p会变色的字/a

a href = id = ppp会变色的字/a

/bodyscript

var chars = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'];

function generateMixed(n) {

var res = ;

for(var i = 0; i n ; i ++) {

var id = Math.ceil(Math.random()*16);

res += chars[id];

}

return res;

}

var num = generateMixed(6);

var p = document.getElementByIdx_x('ppp')

p.style.color = #+num;

var p = document.getElementByIdx_x('pp')

p.style.color = #+num;

var p = document.getElementByIdx_x('p')

p.style.color = #+num;

/script

/html

取消

评论