使用JavaScript更改图像源 [英] Change image source with JavaScript

查看:134
本文介绍了使用JavaScript更改图像源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我是JavaScript的新手(这实际上是我第一次尝试做某事)并且我遇到了一些麻烦。我认为我有足够的知识来完成这项工作,我甚至用Google搜索了可以帮助我解决问题的教程和脚本,但没有任何帮助。

So I'm new with JavaScript (this is actually my first attempt to make something work) and I'm having a bit of trouble. I thought I had enough knowledge to make this work, I've even googled for tutorials and scripts that could help me work this out but nothing really helped.

我可以'似乎改变了图像源,继承了我到目前为止的代码:

I can't seem to change the image source, heres the code that I have so far:

<script type="text/javascript">
    function changeImage(a) {
        document.getElementById("img").src=a.src;
    }
</script>
<div id="main_img">
    <img id="img" src="1772031_29_b.jpg">
</div>
<div id="thumb_img">
    <img src='1772031_29_t.jpg'  onclick='changeImage("1772031_29_b.jpg");'>
    <img src='1772031_55_t.jpg'  onclick='changeImage("1772031_55_b.jpg");'>
    <img src='1772031_53_t.jpg'  onclick='changeImage("1772031_53_b.jpg");'>
</div>

有人可以解释一下我做错了什么吗?或者也许我错过了什么?请帮助我: - )

Could anyone please explain if I'm doing something wrong? Or maybe I'm missing something? Help me please :-)

推荐答案

function changeImage(a) so没有 a.src =>只需使用 a

function changeImage(a) so there is no such thing as a.src => just use a.

演示此处

这篇关于使用JavaScript更改图像源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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