简体   繁体   English

如何在javascript中将图像添加到数组中

[英]how to add images to an array in javascript

Hi i found this code online, its for a memory game created in JavaScript,嗨,我在网上找到了这段代码,它是一个用 JavaScript 创建的记忆游戏,

I want to be able to put images in the array instead of the letters that are there, how do I do it?我希望能够将图像放入数组而不是那里的字母,我该怎么做? Thank You谢谢你

you must add image source (src) to array, not images.您必须将图像源 (src) 添加到数组,而不是图像。 and if you want to change image , just change src.如果你想改变 image ,只需改变 src 。

  <img id="myImage" />
     <script>
         var x = new Array('1.jpg', '2.jpg', '3.jpg');
         var img = document.getElementById("myImage");
         img.setAttribute("src", x[0]);
    </script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM