jQuery fadeIn() 在 IE 中不起作用

发布于 2024-08-30 07:11:36 字数 722 浏览 2 评论 0原文

$(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 之外,其他的都可以用吗?

$(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;
 });

});

Works in everything but IE?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

软糖 2024-09-06 07:11:36

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

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

IE 不喜欢返回 "#id" 但它认为您想要:"http://site.com/currentPage.html#id",这对选择器不起作用:) 如果你从 DOM 元素中获取 .hash ,你就会得到一致的 #id 部分。

您可以找到更多有关为什么发生这种情况的讨论在这个问题中

You can do this to get consistent behavior:

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

IE likes to return not "#id" but instead it thinks you want: "http://site.com/currentPage.html#id", which won't work for a selector :) I you grab the .hash off the DOM element, you get just he #id portion consistently.

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

一抹苦笑 2024-09-06 07:11:36

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

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

$(this).find("a").attr("href") gets you the HREF of the target, not the target. Assuming you're putting the name of a DIV in the href in there that may be correct (I don't know what's in there).

Try alert($(this).find("a").href()) to see if you've got the right element, or just try .show() and see what happens.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文