2013-12-11 70 views

回答

0

最简单的方法是使用jQuery并将事件侦听器添加到<a/>。它会去是这样的:

/* 
* Note that I add an ID to the <a/> tag selector 
* as we don't want to listen to ALL <a/> tags 
* and only a specific one. Make sure to add an ID to you <a/> 
*/ 
$('a#click-to-change-img').on('click',function(evt){ 
    $('#display').attr('src','/assets/img/new-image-file.png'); 
}); 

你也可以做内联JavaScript(我个人不喜欢)

<a href="#" onclick="document.getElementById('display').src='/assets/img/new-image-file.png';return false;"> 
    Click Me 
</a> 

在这两种情况下,我们等待被点击的标签。然后,我们运行一个函数,该函数将标记定位到“display”的“id”并更改其“src”属性的值