java生成一定范圍的隨機數(shù) 用java如何隨機生成顏色?
用java如何隨機生成顏色?//將背景色的值定義成空字符串 varbgColor="" //循環(huán)6次,生成一個隨機的六位數(shù) for(vari=0i<6i ) { bgColor ="" Math
用java如何隨機生成顏色?
//將背景色的值定義成空字符串 varbgColor="" //循環(huán)6次,生成一個隨機的六位數(shù) for(vari=0i<6i ) { bgColor ="" Math.round(Math.random()*9) } //將隨機生成的背景顏色值賦給頁面的背景色。 document.getElementById("test") .style.backgroundColor="#" bgColor 把下面的代碼放在一個空網(wǎng)頁的最后體驗一下。 <SCRIPTlanguage=javascripttype=text/javascript> vara=Math.round(Math.random()*0x1000000) varc="00000".concat(a.toString(16)) document.bgColor="#" c.substr(c.length-6,6) </SCRIPT>