search

Home  >  Q&A  >  body text

如何在html标签内,生成随机数?

我想让标签内的<img src="num.jpg">内的num是随机数,以便每次都能链接到不同的图片。

1.png

素颜素颜2796 days ago2166

reply all(4)I'll reply

  • 唐

    2020-07-14 08:37:24

    Use JS to find random numbers,

    Random number formula: Math.random()*(max-min) min

    Example, find 0-10 Find a random integer between 10-20; Find a random integer between 20 and 30; Find a random integer between 7 and 91

    function geta(max,min){ Function

    var random =Math.random()*(max-min) min; // Find the formula for random numbers       ​ ​ random = Math.floor(random); ​ ​ ​ ​ // Round down (remove decimals directly) Document.write (random "& lt; hr/& gt;"); // output results } geta(0,10); geta(10,20); geta(20,30); geta(7,91);

    reply
    0
  • 唐

    2020-07-14 08:32:17

    Use JS to find random numbers,

    Random number formula: Math.random()*(max-min) min

    2345截图20200714082910.jpg

    reply
    0
  • 数据分析师

    数据分析师2017-10-01 01:11:30

    How to generate random numbers in html tags? -PHP Chinese website Q&A-How to generate random numbers in html tags? -PHP Chinese website Q&A

    Let’s take a look and learn.

    reply
    0
  • 迷茫

    迷茫2017-03-29 09:37:04

    你这图片显示随机数,你能确保任何数字都能有个图片在服务器上面吗,所以你这个随机数应该是有个范围在,或者说,定义一个集合,里面放所有图片随机数,

    var imageNums = [123,221,32];
    function getImageNum(numArray){
        var index = Math.获取随机数,范围是数组下标范围内;
        return numArray[index];
    }

    reply
    1
  • Cancelreply