请问如何把变量的值赋予DIV的背景颜色? 比如说我定义个变量A,这个A是随机生成的颜色代码,我想把这个A的值赋予一个DIV的背景颜色,这样我就可以每次刷新页面都得到不同颜色的DIV方块了。但是不知道应该怎么写。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://www.csrcode.cn/html/txdm/ljwb/3036.htm 看看这个 <div id="x" style="width:90px;height:90px"></div><script type="text/javascript">var d= "#"+Math.floor(Math.random()*Math.pow(2,24)).toString(16);document.getElementById("x").style.background=d;</script> <!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=utf-8" /><title>无标题文档</title><script type="text/javascript">window.onload = function() { var r = parseInt(Math.random().toString().substring(2)) % 256; var g = parseInt(Math.random().toString().substring(2)) % 256; var b = parseInt(Math.random().toString().substring(2)) % 256; //生成3个0-255的随机数 document.getElementById('test').style.backgroundColor = 'rgb(' + r + ',' + g + ',' + b + ')'; //设置背景色}</script></head><body><div id="test" style="width:200px; height:200px;"></div></body></html> 请教javascript中传参数问题 紧急!在规定条数的基础上判断是否合格的问题~~ 如何让内容适应IFRAME的宽度? 请问这样的函数怎么绑定?? 修改注册表启动Activex控件 请帮我看下这代码错在哪里? 如何做类似QQ的窗口效果-窗口的一边到达边线窗口自动移入不可见区域 如何取得子页面的值, 怎样在应用程序和html之间交换信息? 高分求救,我急,如何在DM中用JS来实现3张图片交替显示 JavaScript多级联动的问题 用户注册提交的问题
<div id="x" style="width:90px;height:90px">
</div><script type="text/javascript">
var d= "#"+Math.floor(Math.random()*Math.pow(2,24)).toString(16);
document.getElementById("x").style.background=d;
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
window.onload = function() {
var r = parseInt(Math.random().toString().substring(2)) % 256;
var g = parseInt(Math.random().toString().substring(2)) % 256;
var b = parseInt(Math.random().toString().substring(2)) % 256; //生成3个0-255的随机数
document.getElementById('test').style.backgroundColor = 'rgb(' + r + ',' + g + ',' + b + ')'; //设置背景色
}
</script>
</head><body>
<div id="test" style="width:200px; height:200px;"></div>
</body>
</html>