大家好~我在JS及html 隨機顯示圖片放入以下語法
index = Math.floor(Math.random() * tips.length);
document.write(tips[index]); //顯示幾張照片放幾組
目前圖片只可顯示一張,
若要改成顯示多張,要改哪裡呢?
麻煩直接列給我修改後的語法,謝謝
大家好~我在JS及html 隨機顯示圖片放入以下語法
index = Math.floor(Math.random() * tips.length);
document.write(tips[index]); //顯示幾張照片放幾組
目前圖片只可顯示一張,
若要改成顯示多張,要改哪裡呢?
麻煩直接列給我修改後的語法,謝謝
<!DOCTYPE html>
<html>
<head>
</script>
<script>
var tips = [
{imgUrl:"https://ftp.bmp.ovh/imgs/2021/06/18714484ed0bcedd.jpeg"},
{imgUrl:"https://ftp.bmp.ovh/imgs/2021/06/6c1de67f16cd473a.jpg"},
{imgUrl:"https://ftp.bmp.ovh/imgs/2021/06/f1e72ea4509bfdc3.jpg"},
{imgUrl:"https://ftp.bmp.ovh/imgs/2021/06/0e08adcc12a84823.jpg"},
{imgUrl:"https://ftp.bmp.ovh/imgs/2021/06/c10aede244ea0307.jpg"},
{imgUrl:"https://ftp.bmp.ovh/imgs/2021/06/6aa6957f01aaf8cf.jpg"},
{imgUrl:"https://ftp.bmp.ovh/imgs/2021/06/ffafc9b499c87516.jpg"},
{imgUrl:"https://ftp.bmp.ovh/imgs/2021/06/37f229f7abf99d89.jpg"},
{imgUrl:"https://ftp.bmp.ovh/imgs/2021/06/8ffaa2489786e6f8.webp"},
{imgUrl:"https://ftp.bmp.ovh/imgs/2021/06/a4d652910bbb7826.jpg"},
]
for (var i=0;i<tips.length;i++){
document.write("<img src='"+tips[i].imgUrl+"' style='width:150px;height:150px;'>");
}
</script>
</head>
<body>
</body>
</html>
对你有帮助的话,麻烦点击一下下面的