html image src调用javaScript变量 [英] html image src call javaScript variable

查看:319
本文介绍了html image src调用javaScript变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:我想询问

this is my code: I want to ask

<script type="text/javascript">

var total = 4;

</script>

我该怎么做?

<img src="img/apple_" + total + ".png" id="imageBox"/>

我一直在尝试使用call函数和document.onload,但是它根本不起作用,有人可以救我吗?

I've been try to use call function and document.onload but it's not work at all, can somebody save me?

推荐答案

我想您只是想用javascript更新图片src.

I am supposing you just want to update the image src with javascript.

document.getElementById('imageBox').src = "img/apple_" + total + ".png";

这篇关于html image src调用javaScript变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆