Javascript将一个图像放置在另一个图像上

Javascript将一个图像放置在另一个图像上,javascript,image,Javascript,Image,我有下面的源代码,我想做的是有一个图像出现,如果某个代码输入。诀窍是我需要将该图像置于另一个图像之上。有办法吗 var roomCode = prompt("Please enter the room code", "Enter room code here"); if(roomCode==='102') { /*I want the image to appear at certain coordinates (on top of ano

我有下面的源代码,我想做的是有一个图像出现,如果某个代码输入。诀窍是我需要将该图像置于另一个图像之上。有办法吗

var roomCode = prompt("Please enter the room code", "Enter room code here");
        if(roomCode==='102')
        {
            /*I want the image to appear at certain coordinates (on top of another image).*/
        }

最初创建一个html页面,甚至在其中创建图像。 将“图像显示”属性设置为“无”

试试这个

var roomCode = prompt("Please enter the room code", "Enter room code here");
        if(roomCode==='102')
        {
              load(roomCode+".html");
              $('.image').css('display',block)
        }

只需将以前图像的
src
属性替换为新图像的路径即可

示例:

HTML

只要在每个
if
块中使用
element.setAttribute('src','PATH')


这里有一个例子:

替换之前的图像怎么样?@derek_duncan这是个好主意,但我如何做到这一点,因为我已经映射了底层图像?即将发布答案:)我不太明白你的意思。看起来你正在加载一个新的网页,我不想这样做。你甚至可以在同一个页面中加载特定的div看起来不错。我现在试一试,如果有效,我会将其标记为正确;)
<img id="replacable-img" src="http://www.wallpaperfunda.com/wp-content/uploads/2014/03/images-2.jpg" width="400px" alt="Original image">
<button id="change">Next Image</button> // Just example trigger
var img = document.getElementById('replacable-img');
var button = document.getElementById('change');

change.onclick = function(e) {
  img.setAttribute('src', 'http://www.wired.com/images_blogs/wiredscience/2012/10/kitten-kisses-dog.jpg')
}