将图像添加到另一个图像Javascript(用于关闭按钮)

时间:2014-03-11 14:20:46

标签: javascript html5 image

我正在寻找一种简单的方法,在Javascript中将关闭图标图像添加到另一个图像。我正在尝试在图像的右上角放置一个图标。

代码:

function drawImages(imagevalue){

    var array = localStorage.getItem('images');
    array = JSON.parse(imagevalue);

    //Add HTML to screen:

    //Clear the elements that might already be in the div so they don't appear twice:
    var theDiv = document.getElementById("saveArea");
    while (theDiv.firstChild) {
    theDiv.removeChild(theDiv.firstChild);
    }


    for (var x=0; x < array.length; x++){ 
    //Create image for each value in array:

    var img = document.createElement("img");
    img.src = array[x];
    img.width = 300;
    img.height = 150;
    img.style.marginRight="10px";
    img.className = "saveImg";

            //this image needs to be placed in the top right corner of the
            //image named img. 
    var close = document.createElement("close");
    close.src="close.png";


    document.getElementById("saveArea").appendChild(img);


    }

}

1 个答案:

答案 0 :(得分:0)

CSS不起作用?像position:relative;right:0;top:0;

这样的东西