onclick add image to div(onclick 将图像添加到 div)
问题描述
我正在尝试使用 onclick
在 <div>
中获取图像.
I am trying to get image in a <div>
using onclick
.
现在我正在点击文本.但我想在点击时获取 div 中的图像...
Now I am getting the text on click. but I want to get the image in div on click...
我该怎么做...?
这是我实现的代码,
代码:
<script>
function myFunction()
{
document.getElementById("surprise").innerHTML=images/aftersurprise.png;
}
</script>
当我点击元素时,我应该在惊喜元素上获得 aftersurprise.png
图像...
When I click on element I should get the aftersurprise.png
image on surprise element...
推荐答案
使用
document.getElementById("surprise").innerHTML="<img src='images/aftersurprise.png' />";
这篇关于onclick 将图像添加到 div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!