0
我想完成FreeCodeCamp上的随机引用生成器。我几乎拥有它,但我决定我想更进一步,并使用按钮更改背景图像。我相信背景img是从最初设置背景img的第一个电话缓存的。因此,每次我点击按钮浏览器基本上重新加载缓存的img,而不是重新访问该网站,并拉动新的img。从jQuery缓存中停止图像
我使用的源只是一个网站,每次访问都会返回不同的图像。
我已经尝试添加一个时间戳到URL的结尾,该网站只是在我身上抛出一个无效的地址图像。
<html>
<head>
</head>
<body>
<div class="container-fluid" id="mainDiv">
<div class = "row text-center">
<div class = "col-xs-12 well" id = "quote">
The quote will go here
</div>
</div>
<div class = "row text-center">
<div class = "col-xs-12">
<button id = "getQuote" class = "btn btn-primary">
Get Quote
</button>
</div>
</div>
</div>
</body>
</html>
body{
background-image: ;
}
#mainDiv{
margin: 0 auto;
max-width: 400px;
margin-top: 200px;
}
$(document).ready(function(){
$('body').css('background-image', 'url("https://source.unsplash.com/random")');
$.getJSON("http://quotes.stormconsultancy.co.uk/random.json", function(json){
$("#quote").html('"' +json.quote + '"<br> - ' + json.author);
});
$("#getQuote").on("click", function(){
$('body').css('background-image', 'url("https://source.unsplash.com/random")');
$.getJSON("http://quotes.stormconsultancy.co.uk/random.json", function(json){
$("#quote").html('"' +json.quote + '"<br> - ' + json.author);
});
});
});