//页面加载时执行的代码
<body onload="sj()">
<div style="120px;height:20px;border:1px solid black;float:left;">
<span id="sz1">1</span><span id="sz2">2</span><span id="sz3">3</span><span id="sz4">4</span>
</div>
<button onclick="sj()">刷新按钮</button>
</body>
//将分装函数代入
<script type="text/javascript">
function sj(){
document.getElementById("sz1").innerHTML=sz();
document.getElementById("sz2").innerHTML=sz();
document.getElementById("sz3").innerHTML=sz();
document.getElementById("sz4").innerHTML=sz();
document.getElementById("sz1").style.color=$color();
document.getElementById("sz2").style.color=$color();
document.getElementById("sz3").style.color=$color();
document.getElementById("sz4").style.color=$color();
}
</script>
//分装的随机数
function sz(){
var met= new Array('a','b','c','d','e','f','g','h','i','g','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',"0","1","2","3","4","5","6","7","8","9");
var z1=met[Math.round(Math.random()*(met.length-1))];
return z1;
}
//分装的随机颜色
function $color(){
var r= Math.round(Math.random()*255);
var g= Math.round(Math.random()*255);
var b= Math.round(Math.random()*255);
var rgb="rgb("+r+","+g+","+b+")";
return rgb;
}