2013-03-12 60 views

回答

1

使用下面的代码:

$("#one img").prop("src", "images/img2.png"); 

它将<img>元素的src属性更改为"images/img2.png"

+0

变化'prop'到'attr'阅读http://api.jquery.com/attr/和http://api.jquery.com/prop/ – 2013-03-12 11:48:02

+0

@RohanKumar莫非你告诉我为什么我需要把'prop'改成'attr'? – VisioN 2013-03-12 11:48:41

+0

它取决于jquery版本,检查[this](http://stackoverflow.com/questions/5874652/prop-vs-attr)。 – Praveen 2013-03-12 11:53:27

0

尝试:

$(document).ready(function(){ 
    $('#one').on('click',function(e){ 
     $(this).children('img').attr('src','images/img2.png'); 
     e.preventDefault(); 
    }); 
});