Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 你如何将某些数字随机化?_Javascript_Html_Css - Fatal编程技术网

Javascript 你如何将某些数字随机化?

Javascript 你如何将某些数字随机化?,javascript,html,css,Javascript,Html,Css,我知道如何随机化数字,比如1到100,但不知道某些数字。就像我只想要像1,15,等等。我环顾四周,它太混乱了。有没有更简单的方法?谢谢大家! function getRandom() { return Math.random()1, 15, 30, 45; } 它的所有代码都有一个动画,我希望在动画之后的框中出现一个随机的特定数字 <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> &l

我知道如何随机化数字,比如1到100,但不知道某些数字。就像我只想要像1,15,等等。我环顾四周,它太混乱了。有没有更简单的方法?谢谢大家!

function getRandom() {
return Math.random()1, 15, 30, 45;
}
它的所有代码都有一个动画,我希望在动画之后的框中出现一个随机的特定数字

<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<!DOCTYPE html>
<html>
<head></head>
<title>The Wheel!</title>
<body bgcolor="orange">
<head>
    <style>
        .wheel {
            width: 200px;
            height: 100px;
            left: 600px;
            top: 300px;
            background: green;
            position: relative;
        }

        .animated-wheel {
            -webkit-animation: myfirst4s 2;
            -webkit-animation-direction: alternate;
            animation: myfirst 4s 2;
            animation-direction: alternate;
        }

        @-webkit-keyframes myfirst {
            0% {background: green; left: 600px; top: 300px;}
            33% {background: black; left: 600px; top: 0px;}
            66% {background: red; left: 600px; top: 650px;}
            100% {background: black; left: 600px; top: 0px;}
        }

        @keyframes myfirst {
            0% {background: green; left: 600px; top: 300px;}
            33% {background: green; left: 600px; top: 300px;}
            66% {background: black; left: 600px; top: 0px;}
            100% {background: red; left: 600px; top: 650px;}
        }
    </style>      
</head>
    <div class="wheel"></div>
    <button onclick="startbtn()">Start</button>
    <button onclick="refresh()">Reset</button>
    <button onclick="getRandom()">Number</button>
    <p id="getRandom()"></p>

<script>
startbtn = function() {
$('.wheel').addClass('animated-wheel');
}
function refresh() {
    location.reload();
};
function getRandom() {
var values = [1, 15, 30, 45];
return values[Math.floor(Math.random() * values.length)];
}
</script>


</body>
</html>

您可以移动数组中的数字并返回带有随机索引的拾取

为了在动画之后获取值,可以延迟绘制数值并超时,然后将该值添加到标记中

函数startbtn{ $'.wheel'.addClass'animated-wheel'; setTimeout=>document.getElementById'random'。innerHTML=getRandom,8000; } 函数刷新{ 位置。重新加载; } 函数getRandom{ var值=[1,15,30,45]; 返回值[Math.floorMath.random*values.length]; } .wheel{宽度:200px;高度:100px;左侧:600px;顶部:300px;背景:绿色;位置:相对;} .animated wheel{-webkit动画:myfirst4s 2;-webkit动画方向:alternate;动画:myfirst 4s 2;动画方向:alternate;} @-webkit关键帧myfirst{0%{background:green;left:600px;top:300px;}33%{background:black;left:600px;top:0px;}66%{background:red;left:600px;top:650px;}100%{background:black;left:600px;top:0px;} @关键帧myfirst{0%{background:green;left:600px;top:300px;}33%{background:green;left:600px;top:300px;}66%{background:black;left:600px;top:0px;}100%{background:red;left:600px;top:650px;} 开始 重置 数字

您可以在数组中有数字,然后随机访问索引 函数getRandom{ 设nums=[1,15,30,45] 返回nums[Math.floorMath.random*nums.length] } console.loggetRandom console.loggetRandom
console.loggetrandom和的可能重复项您好!你会在这里找到答案:如果这仍然很难理解,让我们知道它的确切部分是麻烦的,有人可以帮助。数字不会弹出?我试过了,但没有成功

带有一个按钮来激活它,如:numberd您想要一个随机id还是标签中的值?很抱歉让您感到困惑,但我想要一个我已经拥有的动画,以及一个在它后面显示的数字。所以ID标签。我想我该怎么处理丢失的信息?你想要所有的代码吗?