因此,我在这件事中是新手,我需要每次有人刷新页面时创建随机数

发布于 2025-01-24 12:40:00 字数 1551 浏览 3 评论 0原文

这是我的代码,我不知道要输入什么来在表中获取随机数。有人可以帮忙吗?我希望每当有人刷新页面时都会更改数字。该数字必须有5位数字。

<div>
  <br>
</div>
<div class="custd-container custd-bg">
  <table class="custd-bg" cellpadding="0" cellspacing="0">
    <tr>
      <th colspan="12" class="custd-18px custd-bg" style="text-align:center; border-bottom:2px solid #6f5d1a;">LUCKY NUMBER</th>
    </tr>
    <tr>
      <td class="custd-bg" rowspan="2" style="padding-left: 10px;"></td>
      <td class="custd-25px custd-center custd-bg" id="custangka">00001</td>
      <td style="text-align: center;" class="custd-15px custd-bg">LUCKY</td>
    </tr>
    <tr>
      <td style="padding-right: 10px;" class="custd-bg" colspan="3">
        <div class="progress21 progress-moved2 custd-bg" style="padding-left: 3px;">
          <div class="progress-bar21 custd-bg" style="padding-left: 3px;"></div>
        </div>
      </td>
      <td class="custd-bg" style="text-align:left; border-right:2px solid #6f5d1a"></td>
      <td class="custd-bg" colspan="3" style="padding-left: 7px; padding-right: 10px;">
        <div class="progress31 progress-moved11 custd-bg1">
          <div class="progress-bar31 custd-bg"></div>
        </div>
      </td>
      <td class="custd-bg" style="text-align:left; border-right:2px solid #6f5d1a"></td>
    </tr>
  </table>
</div>

我应该怎么办?

Here is my code, i dont know what to input to get random number in my table. Can anyone help please? I want the number to change whenever someone refresh the page. the number must have 5 digits.

<div>
  <br>
</div>
<div class="custd-container custd-bg">
  <table class="custd-bg" cellpadding="0" cellspacing="0">
    <tr>
      <th colspan="12" class="custd-18px custd-bg" style="text-align:center; border-bottom:2px solid #6f5d1a;">LUCKY NUMBER</th>
    </tr>
    <tr>
      <td class="custd-bg" rowspan="2" style="padding-left: 10px;"></td>
      <td class="custd-25px custd-center custd-bg" id="custangka">00001</td>
      <td style="text-align: center;" class="custd-15px custd-bg">LUCKY</td>
    </tr>
    <tr>
      <td style="padding-right: 10px;" class="custd-bg" colspan="3">
        <div class="progress21 progress-moved2 custd-bg" style="padding-left: 3px;">
          <div class="progress-bar21 custd-bg" style="padding-left: 3px;"></div>
        </div>
      </td>
      <td class="custd-bg" style="text-align:left; border-right:2px solid #6f5d1a"></td>
      <td class="custd-bg" colspan="3" style="padding-left: 7px; padding-right: 10px;">
        <div class="progress31 progress-moved11 custd-bg1">
          <div class="progress-bar31 custd-bg"></div>
        </div>
      </td>
      <td class="custd-bg" style="text-align:left; border-right:2px solid #6f5d1a"></td>
    </tr>
  </table>
</div>

What should i do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鱼窥荷 2025-01-31 12:40:00

为了创建随机数,您必须使用JavaScript。
可以生成具有5位数字的随机数,并以ID“ Custangka”这样的ID放入DIV:

function getRndInteger(min, max) {
  return Math.floor(Math.random() * (max - min) ) + min;
}
document.getElementById("custangka").innerHTML = getRndInteger(10000, 99999);

该代码部分从 https://www.w3schools.com/js/js_random.asp

请注意,此数字是在客户端生成的,因此在加载页面的计算机上。这意味着客户端可以控制数字。

In order to create random numbers you will have to make use of JavaScript.
A random number with 5 digits can be generated and put into the div with id "custangka" like this:

function getRndInteger(min, max) {
  return Math.floor(Math.random() * (max - min) ) + min;
}
document.getElementById("custangka").innerHTML = getRndInteger(10000, 99999);

The code is partially taken from https://www.w3schools.com/js/js_random.asp.

Please be aware that this number is generated on the client side, so on the computer that is loading the page. This means that the client can control the number.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文