gpt4 book ai didi

javascript - 使用新图像刷新页面

转载 作者:可可西里 更新时间:2023-10-31 23:39:44 24 4
gpt4 key购买 nike

<分区>

目前我的网站上有一张停滞不前的图片:

    <!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/stylesheets/normalize.css" media="all" rel="stylesheet" />
<link href="/stylesheets/master.css" media="all" rel="stylesheet" />

<script>
window.onload = function () {

var images = [],
i=1, indexImages = true,
prefix = '../image/',
extension = '.jpg';

while (indexImages) {
var a = new XMLHttpRequest(); a.open('GET', prefix+i+extension, false); a.send();

if (a.status != 404) { i += 1; images.push(prefix+i+extension); } else {
indexImages = false;

localStorage['backgroundIndex'] = !localStorage['backgroundIndex']?0:+localStorage['backgroundIndex']+2>images.length?0:+localStorage['backgroundIndex']+1;
document.body.style.backgroundImage = 'url(' + images[+localStorage['backgroundIndex']] + ')';

}
}

}
</script>

<style>
body {
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
background-color: black;

border-bottom: 8px solid #7D8A28;
}

</style>

</head>
<body>
<section id="card">
</section>
</body>
</html>

只是我希望每次页面刷新时它都是不同的图像,所以它会自动更改为 2.jpg、3.jpg、10.jpg 等等。 (有数百种可供选择)

有人可以帮我解决吗?我不太擅长这个,这是我的第一个网站。

谢谢。

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