2011-07-23 38 views
1
<div id="mainContent"> 
<div class="photoShow"></div> 
<div class="photo_nav"></div> 
<div class="photo_caption"> 
<div class="photo_caption_content"></div> 
</div> 

// .photo_content has jQuery content and photo background 
<div id="content"> 
<div class="photo_content"></div> 
<div class="photo_content"></div> 
<div class="photo_content"></div> 
</div> 

    <script> 
    $('.photo_nav a.photo_nav_item').click(function(){ 
var navClicked = $(this).index(); 
var Photo = $('.photo_content').get(navClicked); 
var curPhoto = $(Photo).html(); 
    $(".photo_nav a.photo_nav_item").removeClass('current'); 
    $(".photoShow").removeClass('current'); 
$(this).addClass('selected'); 
$(".photoShow").fadeIn('slow', 'swing'); 
$(".photoShow").html(curPhoto); 
    }); 
    </script> 

    // .photo_content has jQuery properties which runs fine by itself. But with this click  //function, it loses the properties. Using .get, instead of .html i.e. 


$(".photoShow").get(Photo); 

//keeps the contents working but then I lose navigation index property. 
//in conclusion, with .html, it displays correct .photo_content but DOM does not work. 
//With .get, I get .photo_content that works but indexing does not work. 
+1

你的問題不明確。請嘗試更好地描述您的問題。 –

回答

2

不是100%清楚的問題。但.get()和.html()返回從根本上不同的東西。

獲得()返回一個DOM元素

html的()返回(或套)的HTML內容的字符串。

另外請注意,這是沒有意義的:

$(".photoShow").get(Photo); 

除非照片是一個整數,它根據你的代碼是不是。

這有幫助嗎?如果沒有 - 您發佈的代碼的哪一行沒有達到您的期望值?

1

我覺得你做一些困惑:

html()返回第一個匹配的選擇器的HTML內容。所以,如果您有:

<div id='container'><div id='content'>Content</div></div> 

$('#container').html();//returns <div id="content">Content</div> which is a string 

get() retruns DOM元素

<div id='container'><div id='content'>Content</div></div> 

$('#container').get(0);//returns a dom object