【问题标题】:IE6 doesn't like my simple jQuery: Any idea why?IE6 不喜欢我的简单 jQuery:知道为什么吗?
【发布时间】:2011-03-21 09:01:01
【问题描述】:

下面的 jQuery 片段用于顶部有消息的页面,以及在其下方回复消息的所有 cmets。代码在 IE8/Chrome/Firefox 上的工作方式是它“折叠”了初始消息下方的所有 cmets,因此只有它们的主题出现。单击他们的主题,然后将初始消息替换为评论(即,它“伪造”了将每条评论放在自己的页面上的行为)。

问题是 IE6 拒绝使用代码;当 IE6 访问者登陆页面时,所有 cmets 都拒绝折叠,点击标题没有任何反应。

有谁知道如何纠正这个问题以使 JS ie6 兼容?

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).next().children('.forumthreadtitle').show());
        }

$('.forumthreadtitle').click(function() { 
    pageTracker._trackPageview("/comment?page=" + document.location.pathname);
    flip($(this)); 
    } );
});

以下是一些 HTML 示例(尝试将其简化一下,以便于理解):

<DIV id="first-post">
       <H2 class="title"><A href="test.html">TEST</A></H2>
      <SPAN class="submitted">Submitted by Big J on July 26, 2010 - 3:26pm</SPAN> 
  <DIV class="content">First Post</DIV>
</DIV>

<DIV id="comments">
  <A id="comment-1643951"></A>
<DIV class="comment comment-published clear-block">
  <H3 class="forumthreadtitle"><A href="test.html#comment-1643951" class="active">Test Reply....</A>
  <DIV class="submitted comment-info">Submitted by test on July 26, 2010 - 4:49pm.</DIV>
  </H3>

  <DIV class="content" style="display: none; ">
  Test Comment Content
  </DIV>
</DIV>
</DIV>

【问题讨论】:

标签: jquery cross-browser internet-explorer-6


【解决方案1】:

我建议你尝试 2 件事:

  1. 使用 jQuery(function() { }) 代替 $(document).ready(function() { });
  2. 将 jQuery 代码移动到 HTML 页面的底部。

【讨论】:

  • 感谢您的建议!我现在就试试
  • 我将 $(document) 更改为 jQuery,我的代码已经在页面底部 - 仍然没有效果 :(
猜你喜欢
  • 2011-09-22
  • 1970-01-01
  • 2015-11-20
  • 2012-05-19
  • 2018-03-14
  • 2011-05-17
  • 2021-11-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多