Onclick使用jQuery更改另一个div中的图像源

时间:2014-03-10 12:06:36

标签: javascript jquery html css

我有3个小div,当你点击我想在我的页面顶部播放一个更大的div时,唯一的问题是我无法让它工作,我不知道为什么。

我正在尝试更新

$('.highlight-image').on('click', function (e) {

console.log('clicked');

var currImg = $(this).find('.imageHolder').children('img').attr('src');
var currP = $(this).find('blockquote').text;

var targetImg = $('.featuredTestimonial img');
var targetName = $('.featuredTestimonial h2');
var targetP = $('.featuredTestimonial p');

$('.featuredTestimonial p').text = currP;
$('.featuredTestimonial img').attr('src'); = currImg;

});

http://jsfiddle.net/6qcpg/2/

3 个答案:

答案 0 :(得分:3)

更改

$('.featuredTestimonial img').attr('src'); = currImg;

$('.featuredTestimonial img').attr('src', currImg);

答案 1 :(得分:1)

试试这个:

$('.featuredTestimonial p').text(currP);
$('.featuredTestimonial img').attr('src', currImg);

而不是

$('.featuredTestimonial p').text = currP;
$('.featuredTestimonial img').attr('src'); = currImg;

JSFIDDLE

答案 2 :(得分:1)

使用它

工作http://jsfiddle.net/JFTTe/

 $('.highlight-image').on('click', function(e) {
     var currImg = $(this).find('.imageHolder').children('img').attr('src');
     var currP = $(this).find('blockquote').text();

     var targetImg = $('.featuredTestimonial img');
     var targetName = $('.featuredTestimonial h2');
     var targetP = $('.featuredTestimonial p');

     $('.featuredTestimonial p').text(currP);
     $('.featuredTestimonial img').attr('src', currImg);
 });