2012-04-07 27 views
0

我有一個問題:爲什麼在IE 8jQuery的IE 8的顯示/隱藏不工作

$(function() { 
    $('.title .hide').showContent(); 
}); 

$.fn.showContent = function() { 
    return this.each(function() { 
     var box = $(this); 
     var content = $(this).parent().next('.content'); 

     box.toggle(function() { 
      content.slideUp(500); 
      $(this).css('background-position', 'right bottom'); 
     }, function() { 
      content.slideDown(500); 
      $(this).css('background-position', 'right top'); 
     }); 

    }); 
}; 

而且這方面的工作,這是不工作?

$(function() { 
    $('.title .hide.show').hideContent(); 
}); 

$.fn.hideContent = function() { 
    return this.each(function() { 
     var box = $(this); 
     var content = $(this).parent().next('.content'); 

     box.toggle(function() { 
      content.slideDown(500); 
      $(this).css('background-position', 'right top'); 
     }, function() { 
      content.slideUp(500); 
      $(this).css('background-position', 'right bottom'); 
     }); 

    }); 
}; 

我想這兩個選項工作,但我不知道爲什麼二是沒有在IE 8的工作,我希望somewone能幫助我。

+0

這兩種功能是否可能會相互干擾?您在所有調用'hideContent()'的元素上調用'showContent()',如果使用唯一類標識元素,會發生什麼? – 2012-04-07 20:24:35

+0

否我有並將js更改爲.title .hide和.title .show,但仍然沒有運氣... – Maanstraat 2012-04-07 20:35:19

+0

您可以創建[ jsFiddle](http://jsfiddle.net)問題的演示? – 2012-04-07 20:37:39

回答

1


jQuery有內置的功能,例如隱藏()和show()。
試試看。
ex:$('input#id').hide();
同樣使用類選擇器並不是一個好主意,因爲性能會受到影響。
嘗試使用ID's。

-1

它看起來像你只是調用hideContent()的一個元素與一個顯示類,它是在類的標題中的隱藏類。 .hide.show是嵌套的兩個不同的類。

.title僞 .hide .show

jQuery是一個.title僞

尋找與.show元素在.hide如果你不是取代hideContent二號線切換()搭配:

$('.title .show').hideContent(); 
$('.title .hide').hideContent(); 
+0

Ahh oke,所以這是行不通的:隱藏一個元素? – Maanstraat 2012-04-07 20:19:38

+0

這是不正確的。 jQuery選擇器正在尋找一個元素,其中的'show'和'hide'類都在類'title'的元素中。 – 2012-04-07 20:21:18

+0

我改變了它,但它現在仍然在IE 8中工作...顯示和隱藏正在工作,但隱藏和顯示不起作用。 – Maanstraat 2012-04-07 20:24:35

0

,如果你使用jQuery然後在下面的JavaScript使用, 它可以爲您

jQuery(this).hide(); 
jQuery(this).show(); 
0

我想這是在IE8/JQ的錯誤有用。 請嘗試:

$(id_to_hide).css("display", "none"); 
$(id_to_show).css("display", "inline-block");