How can I change the src
attribute of an img
tag using javascript?(如何使用javascript更改img
标签的src
属性?)
<img src="../template/edit.png" name=edit-save/>
at first I have a default src which is "../template/edit.png" and I wanted to change it with "../template/save.png" onclick.(起初我有一个默认的src是“../template/edit.png”,我想用“../template/save.png”onclick更改它。)
UPDATED: here's my html onclick:(更新:这是我的html onclick:)
<a href='#' onclick='edit()'><img src="../template/edit.png" id="edit-save"/></a>
and my JS(和我的JS)
function edit()
{
var inputs = document.myform;
for(var i = 0; i < inputs.length; i++) {
inputs[i].disabled = false;
}
}
I've tried inserting this inside the edit(), it works but need to click the image twice(我已经尝试在edit()中插入它,它可以工作,但需要单击图像两次)
var edit_save = document.getElementById("edit-save");
edit_save.onclick = function(){
this.src = "../template/save.png";
}
ask by Jam Ville translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…