下面是代码的运行效果;当点击刷新的事件数字都会随机改变;

<?php
header('Content-Type:text/html;charset=utf-8');
require 'header.php';
echo '<script>
//JavaScript 的点击刷新事件,涉及reload();
function show(){
location.reload();
}
</script>';
$red_ball=range(1,33);
$temp=array_rand($red_ball,6);
shuffle($temp);//打乱顺序
//在单位球前面加前导零
foreach($temp as $i){
$red[]= $red_ball[$i]<10?'0'.$red_ball[$i]:$red_ball[$i];
}
$blue_ball=mt_rand(1,16);
$blue=$blue_ball<10?'0'.$blue_ball:$blue_ball;
foreach($red as $value){
echo '<div style="text-align:center;line-height:40px;background:red;width:40px;height:40px;border-radius:20px;float:left;"><span style="color:white;">'.$value.'</span></div> ';
}
echo '<div style="text-align:center;line-height:40px;background:skyblue;width:40px;height:40px;border-radius:20px;float:left;">'.$blue.'</div>';
//添加一个按钮绑定一个点击刷新时间
echo '<button style="position:absolute;top:100px;left:40px;width:180px;height:35px;background:skyblue;border-radius:17px;" onclick=show()>刷新</button>';
?>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号