<!DOCTYPE?html>
<html>
<head>
<meta?charset="UTF-8">
<title>Document</title>
<style?type="text/css">
div{
width:50px;?height:50px;?background-color:#F00;?border-radius:25px;float:left;text-align:center;font-size:35px;line-height:50px;color:#FFF;
}
input{margin-left:?100px;font-size:?20px;}
</style>
</head>
<body>
<?php
$nu='';
$red=range(1,33);
????????//?range()?函數(shù)創(chuàng)建一個包含指定范圍的元素的數(shù)組。
$blue=mt_rand(1,16);
????????//?mt_rand()?使用?Mersenne?Twister?算法返回隨機(jī)整數(shù)。
????????$redd=array_rand($red,2);
????????//shuffle($redd);
????????//?array_rand()?函數(shù)從數(shù)組中隨機(jī)選出一個或多個元素,并返回。
????????$blue_d=$blue<10?"0".$blue:$blue;
????????//?echo?$blue_d;
?????>
<body>
??<div?></div><div></div><div></div><div></div><div></div><div??class="ball_6"></div><div??class="ball_7"></div>??????????
????<br/><br/><br/><br/>
????<input?type="button"?value="賭博一下"?onclick="tcon()"?/>
????<script?type="text/javascript">
????????function?tcon(){
?????var?ball=document.getElementsByTagName("div");?//獲取全部的div;???????
????????//?alert(allball);
?????????????//?alert(ball);
????????//?alert(ball.length);
????????var?index?=?Math.floor((Math.random()*6+1));
????????//隨機(jī)藍(lán)球的位置;
????????//var?aon=<?php?echo?$redd;??>;
????????for(var?j=0;j<ball.length;j++){
????????????var?allball=ball[j].className;
????????????//?alert(allball);
????????????if?(allball!=index)?{
????????????//ball[j].innerHTML=aon;
????????????}//把數(shù)字傳入球
????????//?alert(ball[index].className);
????????????????}
????????//全部定義為紅球;
????????for?(var?i=0;?i?<ball.length;?i++)?{
????????????ball[i].style.backgroundColor="red";
????????}
????????//定義籃球加傳入隨機(jī)數(shù)字;
????????ball[index].style.backgroundColor="blue";
????????var?con=<?php?echo?$blue_d;??>;
????????ball[index].innerHTML=con;
????????????
????}
????</script>
</body>
</html>
array_rand獲取多個隨機(jī)數(shù)報(bào)錯,求大牛
俠客島的含笑
2016-11-04 14:39:09