为什么我的随机图像生成器不显示?

时间:2016-09-24 20:16:49

标签: javascript html

我的随机图像不会显示。我甚至通过一个html验证器运行它仍然无法找到错误。

function showImg() {
        /*
            The showImg() function displays a random image from the 0.png through 9.png files. The random image is designed to thwart hackers attemting to enter the library records database by requiring visual confirmation.

        */

        var imgNumber = randomInteger(9):// Return a random number from 0 to 9
        document.write ("<img src='" + imgNumber + ".png' alt=' ' />");
        }




      </script>



<script type="text/javascript">
                    showImg();
                    showImg();
                    showImg();
                    showImg();
                    showImg();
                </script>

2 个答案:

答案 0 :(得分:1)

# Maximum number of validators/replicas we expect in the network # Keep the "N" in quotes, or it will be interpreted as "false". "N": 4 调整为

showImg

对于function showImg() { var imgNumber = randomInteger(9);// Return a random number from 0 to 9 document.body.innerHTML += "<img src=" + imgNumber + ".png alt='' />"; } 功能,您可以使用

randomInteger

另见Math.random()

plnkr http://plnkr.co/edit/VTaRXAsXoAiwVTiy7yh7?p=preview

答案 1 :(得分:0)

您的图片是否存储在与您呼叫的网页相同的文件夹中?如果它们在子文件夹中,那么您显然需要在代码中指定路径 - 相对路径或绝对路径。