html怎么让字体得到随机颜色

html怎么让字体得到随机颜色,第1张

<!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/htmlcharset=gb2312" />

<title>会变色的字</title>

</head>

<body>

<div ><b><a href = "" id = "ppp">会变色的字</a></b>

<a href = "" id = "pp">会变色的字</a>

<a href = "" id = "p">会变色的字</a>

<a href = "" id = "ppp">会变色的字</a>

</body><script>

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 = 0i <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>

<div id="rand"></div>

var n=document.getElementById('rand')

n.style.background(rand(0,255),rand(0,255),rand(0,255))


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/7309589.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-04
下一篇 2023-04-04

发表评论

登录后才能评论

评论列表(0条)

保存