代码之家  ›  专栏  ›  技术社区  ›  Jaime

使用jQuery.support检测IE6

  •  34
  • Jaime  · 技术社区  · 16 年前

    有人知道如何使用jquery.support测试IE6(而不是IE7)的特定内容吗?

    我的问题是IE6只支持:hover psuedo类用于锚元素,而IE7确实支持所有元素(如FF、Chrome等)。因此,如果浏览器不支持,我想做一些特别的事情:悬停所有元素。..因此,我需要一种方法来测试此功能。(不想使用jQuery.browser)。有什么想法吗?

    8 回复  |  直到 12 年前
        1
  •  55
  •   FriendOfFuture    16 年前

    虽然检查功能支持而不是用户代理是一种很好的做法,但没有简单的方法可以使用JavaScript检查css属性的支持。我建议你要么按照上面海报上的建议使用条件注释,要么使用jQuery.browser。一个简单的实现(未经过性能或错误验证)可能如下:

    if ($.browser.msie && $.browser.version.substr(0,1)<7) {
      // search for selectors you want to add hover behavior to
      $('.jshover').hover(
        function() {
          $(this).addClass('over');
        },
        function() {
          $(this).removeClass('over');
        }
    }
    

    在你的标记中,将.jshover类添加到你想要悬停css效果的任何元素中。在你的css中,添加这样的规则:

    ul li:hover, ul li.over { rules here }
    
        2
  •  21
  •   scunliffe    12 年前

    您可以使用特定于Microsoft Internet Explorer的 Conditional Comment 将特定代码仅应用于IE6。

    <!--[if IE 6]>
      Special instructions for IE 6 here... e.g.
      <script>...hook hover event logic here...</script>
    <![endif]-->
    
        3
  •  20
  •   Andrew    16 年前

    Thickbox用途

    if(typeof document.body.style.maxHeight === "undefined") {
        alert('ie6');
    } else {
        alert('other');
    }
    
        4
  •  2
  •   cletus    16 年前

    这是一个例子,说明我们应该退一步,问你为什么这样做。

    通常是创建菜单。如果是这样,我强烈建议你省去一些麻烦,使用像这样的插件 superfish

    如果没有,我建议你使用 jQuery hover() 事件监听器。例如:

    $("td").hover(function() {
      $(this).addClass("hover");
    }, function() {
      $(this).removeClass("hover");
    });
    

    会做你想做的事。

        5
  •  1
  •   Piotr Sarnacki Piotr Sarnacki    16 年前

    我会使用Whatever:hover- http://www.xs4all.nl/~peterned/csshover.html

    它使用行为,对我来说效果很好。

        6
  •  1
  •   Andres SK    14 年前

    只是为了好玩(不使用jQuery.support):

    $(document).ready(function(){
        if(/msie|MSIE 6/.test(navigator.userAgent)){
            alert('OMG im using IE6');
        }
    });
    

    你也可以通过php来实现

    <?
    if(preg_match('/\bmsie 6/i', $ua) && !preg_match('/\bopera/i', $ua)){
        echo 'OMG im using IE6';
    }
    ?>
    
        7
  •  0
  •   alex2k8    16 年前

    jQuery.support没有可检测的属性:悬停支持 http://docs.jquery.com/Utilities/jQuery.support

    但也许你可以简单地使用hover()事件 http://docs.jquery.com/Events/hover

        8
  •  -2
  •   Mithun Sreedharan Kuldeep Modi    14 年前
    if ($.browser.msie && parseInt($.browser.version, 10) == 6) {
      alert("I'm not dead yet!"); 
    }