如何使用javascript删除同一页面上的图像?

时间:2013-10-25 06:58:01

标签: javascript jsp

我尝试了一些代码..

function loadImages() {

     var img = document.createElement("img");
        img.src = "/images/answers/${record1.answer_id}.png";
        img.id = "answer_id";
}
function removeFile(){
     var elements = document.getElementsById('/images/answers/${record1.answer_id}.png').document.getElementsByTagName('img');
}

2 个答案:

答案 0 :(得分:0)

试试这个:

var elements = document.getElementById("answer_id");
elements.parentNode.removeChild(elements);

document.getElementsById('/images/answers/${record1.answer_id}.png')中你试图使用'src'来获取元素,而getElementsById必须是getElementById

答案 1 :(得分:0)

隐藏元素:

document.getElementById('answer_id').style.display = 'none';

完全删除

document.getElementById('answer_id').remove();