2011-07-23 85 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