用javascript更改图像

时间:2015-03-09 22:09:14

标签: javascript html image

我想在点击时更改图像箭头,目前我有http://codepen.io/anon/pen/qEMLxq,但点击时更改了当前图片但不隐藏 -

 <a id="Boton1" class="button" onClick="showHide()" href="javascript:void"><center>
    Lípidos<br>
     <img src="http://sakapa.itmui.com/todo/www/img/flecha_abajo.png" width="24" height="13" alt=""/>
  </center></a>

2 个答案:

答案 0 :(得分:0)

Puedescambiardinámicamentelaimagen con la propiedad .src,peroteaconsejaríaponerleun ID para que laidentifiquesmásfácilmente。 Lo puedes hacer directamente en JavaScript o de preferencia con jQuery。

答案 1 :(得分:0)

您的图片箭头没有任何ID。

您需要提供诸如

之类的ID
<img id="flecha_abajo" />

然后在你的函数JavaScript showHide()中你需要做

document.getElementById("flecha_abajo").style.display = none;