Javascript 帮我诊断这个jQuery循环/书签哈希问题?
我在让jquery在100%的时间内正确呈现时遇到了一些问题—我正在使用的代码位于下面。它的目的是通过隐藏除回复主题以外的所有内容来“模拟”一个线程论坛的感觉——当点击主题时,第一篇帖子就会被回复取代 您可以在此处看到一个正在运行的示例: 问题是,当人们通过URL中的书签登录时,脚本无法正常工作,例如: 具体来说,出现的问题是出于某种原因,书签入口点以下的所有帖子都会被复制两次。我不明白为什么会发生这种事——有什么想法吗 我在这件事上非常紧张-非常感谢任何帮助/指导Javascript 帮我诊断这个jQuery循环/书签哈希问题?,javascript,jquery,jquery-selectors,Javascript,Jquery,Jquery Selectors,我在让jquery在100%的时间内正确呈现时遇到了一些问题—我正在使用的代码位于下面。它的目的是通过隐藏除回复主题以外的所有内容来“模拟”一个线程论坛的感觉——当点击主题时,第一篇帖子就会被回复取代 您可以在此处看到一个正在运行的示例: 问题是,当人们通过URL中的书签登录时,脚本无法正常工作,例如: 具体来说,出现的问题是出于某种原因,书签入口点以下的所有帖子都会被复制两次。我不明白为什么会发生这种事——有什么想法吗 我在这件事上非常紧张-非常感谢任何帮助/指导 function fli
function flip(comment) {
$('#first-post').replaceWith(comment.closest(".comment").clone().attr('id','first-post'));
$('#first-post').children('.forumthreadtitle').children('.comment-info').empty();
$('#first-post').find(':hidden').fadeIn('slow');
$('html, body').animate({scrollTop:0}, 'fast');
return false;
}
$(document).ready(
function(){
$('.submitted').each(function() {
$(this).clone().addClass('comment-info').appendTo($(this).siblings('.forumthreadtitle'));
if(!$(this).parent('#first-post').html()) {
$('#first-post').children('span.taxonomy').clone().appendTo($(this));
}
});
$('.display_mode').html('Show All Replies');
expandedMode = false;
$('.display_mode').click(function() {
if ( expandedMode == false ) {
$('.forumthreadtitle').siblings().show();
$(this).html('Collapse Replies');
expandedMode = true;
}
else
{
$('.forumthreadtitle').siblings().hide();
$(this).html('Show All Replies');
expandedMode = false;
}
});
$('.forumthreadtitle').siblings().hide();
if(window.location.hash) {
flip($(window.location.hash).nextAll().children('.forumthreadtitle').show());
}
$('.forumthreadtitle').click(function() {
pageTracker._trackPageview("/comment?page=" + document.location.pathname);
flip($(this));
} );
});
您可能需要在
翻转中使用next()
而不是nextAll()
flip($(window.location.hash).next().children('.forumthreadtitle').show());
nextAll()!非常感谢你,你给我的生命增添了岁月:)