<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.
最佳答案
这个问题不是 100% 清楚。但是 .get() 和 .html() 返回根本不同的东西。
.get() 返回一个 DOM 元素
.html() 返回(或设置)一个 HTML 内容字符串。
另请注意,这没有意义:
$(".photoShow").get(Photo);
除非 Photo 是一个整数,根据您的代码,它不是一个整数。
这有帮助吗?如果不是 - 您发布的代码中的哪一行没有达到您的预期?
关于jquery - 当使用 .html 获取 jQuery 内容时,该内容会丢失 jQuery 功能。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6799916/