【发布时间】:2023-03-12 06:47:02
【问题描述】:
我一直在使用以下代码生成随机图像,但没有显示任何图片。
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
var theImages = new Array()
theImages[0] = '<img class="atvi-image-image" alt=""src="/content/dam/atvi/callofduty/blackops2/cod-bo2/dlc/mdlc-calling-card-flags.png" title="" height="467" width="675">'
theImages[1] = '<img class="atvi-image-image" alt="" src="/content/dam/atvi/callofduty/blackops2/cod-bo2/dlc/mdlc-nuketown-zombies.png" title="" height="732" width="1084">'
theImages[2] = '<img class="atvi-image-image" alt="" src="/content/dam/atvi/callofduty/blackops2/cod-bo2/dlc/mdlc-extra-slots.png" title="" height="480" width="752">'
theImages[3] = '<img class="atvi-image-image" alt="" src="/content/dam/atvi/callofduty/blackops2/cod-bo2/dlc/mdlc-nuketown-2025.png" title="" height="412" width="683">'
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(){
document.write(theImages[whichImage]);
}
</script>
</head>
<body>
<SCRIPT LANGUAGE="JavaScript">
showImage();
</script>
</body>
</html>
提前感谢您的帮助!
【问题讨论】:
-
您在 'document.write' 调用中缺少 src="" 的结束引号和 img 标记 ('/>') 的结尾
-
这些天人们不打扰结束行吗?
; -
@Wezly 他们为什么要这样做?
-
你的 javascript Chuck 的许多行。 @Ian我不知道,我问的原因-我仍然没有良好的习惯,我写的其他语言更加挑剔并且需要它们。我想这只是一个好习惯..
-
@jascha 当他们将
return true拆分为多行时,事物中断,分号与否。我认为分号也不会促使说的菜鸟不拆分回报。
标签: javascript random image