如何在html标签内,生成随机数?
素颜
素颜 2017-03-29 09:36:02
0
4
2159

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

1.png

素颜
素颜

越努力越幸运!!!

reply all(4)
唐

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);

唐

Use JS to find random numbers,

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

2345截图20200714082910.jpg

数据分析师

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.

迷茫

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

var imageNums = [123,221,32];
function getImageNum(numArray){
    var index = Math.获取随机数,范围是数组下标范围内;
    return numArray[index];
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!