array_rand获取多个随机数报错,求大牛

<!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() 函数创建一个包含指定范围的元素的数组。
$blue=mt_rand(1,16);
        // mt_rand() 使用 Mersenne Twister 算法返回随机整数。
        $redd=array_rand($red,2);
        //shuffle($redd);
        // array_rand() 函数从数组中随机选出一个或多个元素,并返回。
        $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));
        //随机蓝球的位置;
        //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;
            }//把数字传入球
        // alert(ball[index].className);
                }
        //全部定义为红球;
        for (var i=0; i <ball.length; i++) {
            ball[i].style.backgroundColor="red";
        }
        //定义篮球加传入随机数字;
        ball[index].style.backgroundColor="blue";
        var con=<?php echo $blue_d; ?>;
        ball[index].innerHTML=con;
            
    }
    </script>
</body>
</html>


侠客岛的含笑
浏览 52回答 0
0回答
打开App,查看更多内容
随时随地看视频慕课网APP