gpt4 book ai didi

javascript - 如何使用按钮刷新浏览器页面?

转载 作者:行者123 更新时间:2023-11-28 19:22:39 25 4
gpt4 key购买 nike

我一直在学习 JavaScript,并一直致力于开发可定制的随机数生成器。如果您决定要做不止一项,则必须刷新它。我尝试过循环,但这使它变得无限。这是代码:

<DOCTYPE! html>
<body>
<script>
//This is a simple thingy, to randomly pick a number under a certain number

//This is how we get what they want the max to be
var input = prompt("Pick a number to be the maximum");

//This is what it will output
var output = Math.floor(Math.random() * (input + 1));
//The reason for +1 is that it never reaches the max number without it

//This is the output
alert(output);
</script>
</body>

最佳答案

你可以这样做:

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Reload page</button>

<script>
function myFunction() {
location.reload();
}
</script>

</body>
</html>

W3Schools

关于javascript - 如何使用按钮刷新浏览器页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28507453/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com