如何在img src中添加动态值 [英] how to add dynamic values in img src
本文介绍了如何在img src中添加动态值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< img src ="c:users \ xxxxx \ xxxx \ ________"/>
我想通过javascript给出空白行的值.将值设为xxxx.jpg.
var a = xxxx.jpg.
如何在src网址中使用"var a",以便获取图像
<img src="c:users\xxxxx\xxxx\________"/>
i want to give the value for the blank line through javascript. let the value be xxxx.jpg.
var a=xxxx.jpg.
how to use the "var a" inside the src url so that i can get the image
推荐答案
<body onload=""setImageSrc();"><br" mode="hold" /><img id="img1" src="c:users\xxxxx\xxxx\________"/>
</body
<script language="javascript">
function setImageSrc()
{
var img1=document.getElementById('img1');
img1.src='a.jpg';
}
</script>
您可以将脚本编写为:
You can write the script as:
function LoadImages() {
searchPic = new Image();
searchPic.onload=function () {
document["pic1"].src = "XXXX/YYYY/search.png";
}
searchPic.src = "XXXX/YYYY/search.png";
}
这篇关于如何在img src中添加动态值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文