[英]Randomize images when refreshing page js html
這是一個應該使用DIV HTML而不是document.write隨機渲染圖像的代碼,有沒有人有想法?
<script>
var theImages = new Array()
//Random-loading images
theImages[0] = '/img/pirc/hostnger-he.png' // replace with names of images
theImages[1] = '/img/pirc/hostnger-en.png' // replace with names of images
var j = 0
var p = theImages.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
preBuffer[i] = new Image()
preBuffer[i].src = theImages[i]
}
var whichImage = Math.round(Math.random()*(p-1));
function showImage(){
if(whichImage==0){
$('.hostnger').html('<a href ="https://www.hostg.xyz/SH1An" target="_blank"><img class="hostnger" src="'+theImages[whichImage]+'"></a>')
}
else if(whichImage==1){
$('.hostnger').html('<a href ="https://www.hostg.xyz/SH1Ar" target="_blank"><img class="hostnger" src="'+theImages[whichImage]+'"></a>')
}
}
</script>
<div class="hostnger"></div>
在此處刷新pageenter代碼時隨機化圖像
你在哪里實際調用showImage函數?
你應該添加
showImage();
某處。
你是否包括jQuery?
$('.hostnger')
是一個jQuery調用,你不在任何地方包括jQuery。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.