【问题标题】:jQuery fadeIn() not working in IEjQuery fadeIn() 在 IE 中不起作用
【发布时间】:2011-02-13 13:48:16
【问题描述】:
$(document).ready(function() {

 //Default Action
 $(".tab_content").hide(); //Hide all content
 $("ul.tabs li:first").addClass("active").show(); //Activate first tab
 $(".tab_content:first").show(); //Show first tab content

 //On Click Event
 $("ul.tabs li").click(function() {
  $("ul.tabs li").removeClass("active"); //Remove any "active" class
  $(this).addClass("active"); //Add "active" class to selected tab
  $(".tab_content").hide(); //Hide all tab content
  var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
  $(activeTab).fadeIn("slow"); //Fade in the active content
  return false;
 });

});

在除 IE 之外的所有应用程序中都可以使用?

【问题讨论】:

  • 而不是 return false 你应该使用 preventDefault()
  • 嗯。我不希望任何涉及 alpha 混合的东西在 IE 中正常工作,但也许这只是因为它过去对 PNG 的支持有多糟糕......

标签: jquery internet-explorer jquery-animate fadein


【解决方案1】:

您可以这样做以获得一致的行为:

var activeTab = $(this).find("a").get(0).hash;

IE 不喜欢返回 "#id",而是认为你想要返回:"http://site.com/currentPage.html#id",这对选择器不起作用 :) 我从 DOM 元素中获取 .hash,你得到的只是他 @987654326 @ 部分一致。

You can find a bit more discussion on why this happens in this question

【讨论】:

    【解决方案2】:

    $(this).find("a").attr("href") 为您获取目标的 HREF,而不是目标。假设您将一个 DIV 的名称放在那里的 href 中,这可能是正确的(我不知道那里有什么)。

    试试alert($(this).find("a").href()) 看看你是否找到了正确的元素,或者试试.show() 看看会发生什么。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多