js隨機生成驗證碼和顏色

//頁面加載時執行的代碼javascript

<body onload="sj()">java

<div style="width: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>dom

</body>函數

//將分裝函數代入spa

<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();
}ip

</script>get

//分裝的隨機數io

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

//分裝的隨機顏色cli

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;}

相關文章
相關標籤/搜索