2009-06-15 111 views
1

目前,這是行不通的,除了slide.src未定義,因爲默認情況下,slide.src首先查找圖像src標籤,但圖像src標籤現在在div屬性中。jQuery一般問題(循環插件)

那麼我怎樣才能改變javascript + slide.src +(或獲取)div屬性內的圖像。

查看

<div id="properties"> 
<?php foreach($search_results->result() as $row) :?> 
<div id="<?=$row->mls_listing_id?>"><br> 
Listing ID : <?=$row->mls_listing_id?><br> 
State: <?=$row->sale_price?><br> 
State: <?=$row->mls_state_code?><br> 
MLS Office: <?=$row->mls_office_name?><br> 
Office Number: <?=$row->mls_office_phone?><br> 
Photo: **<img src="<?=$row->photo_url?>" width="175" height="137" /**><br> 
</div><!--END specific id div --> 
<?php endforeach; ?> 

</div><!--End Properties DIV --> 

的JavaScript

$('#properties') 
.before('<ul id="propnav">') 
.cycle({ 
    fx: 'scrollHorz', 
    next:'#next', 
    prev:'#prev', 
    pager: '#propnav', 
    delay: -1000 , 
    // callback fn that creates a thumbnail to use as pager anchor 
    pagerAnchorBuilder: function(idx, slide) { 
     return '<li><a href="#">**<img src="' + slide.src + '"** width="50" height="50" /></a></li>'; 
    } 
}); 

回答

1

要獲得包含在div幻燈片圖像,你需要使用:$(slide).children('img').attr('src')

下面是完整的代碼:

$('#properties') 
.before('<ul id="propnav">') 
.cycle({ 
    fx: 'scrollHorz', 
    next:'#next',  
    prev:'#prev', 
    pager: '#propnav', 
    delay: -1000 , 
    // callback fn that creates a thumbnail to use as pager anchor 
    pagerAnchorBuilder: function(idx, slide) { 
     return '<li><a href="#">**<img src="' + $(slide).children('img').attr('src') + '"** width="50" height="50" /></a></li>'; 
    } 
}); 
+0

謝謝你這麼多它奇妙的作品,我仍然在學習jQuery和JS一般。 再次感謝。 – jBeas 2009-06-16 02:06:43

0

非常感謝José!我需要同樣的事情,但我是一個很大的差;)

$(slide).children('div').children('span').children('a').children('img').attr('src')