使用jQuery.support检测IE6 [英] Detecting IE6 using jQuery.support

查看:99
本文介绍了使用jQuery.support检测IE6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都对如何使用jquery.support测试IE6(而非IE7)特定的东西有任何想法吗?

Anyone have any ideas on how to test for something specific for IE6 (and not IE7) using jquery.support?

我的问题是IE6仅对锚元素支持:hover psuedo-class,而IE7对所有元素(如FF,Chrome等)都支持它.因此,在浏览器不支持所有元素:hover的情况下,我想做一些特别的事情,因此我需要一种测试此功能的方法. (不想使用jQuery.browser).有什么想法吗?

My problem is that IE6 supports :hover psuedo-class only for anchor elements and IE7 does support it for all elements (as FF, Chrome, etc). So I want to do something special in case the browser does not support :hover for all elements... thus I need a way to test for this feature. (don't want to use jQuery.browser). Any ideas?

推荐答案

虽然检查功能支持而不是用户代理是一种好习惯,但是没有简单的方法来检查诸如使用JavaScript对css属性的支持.我建议您要么遵循上述使用条件注释的海报建议,要么使用jQuery.browser.一个简单的实现(未经验证的性能或错误)可能如下所示:

While it's good practice to check for feature support rather then user agent, there's no simple way to check for something like support of a css property using JavaScript. I recommend you either follow the above posters suggestion of using conditional comments or use jQuery.browser. A simple implementation (not validated for performance or bugs) could look like this:

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中,添加如下规则:

In your markup, add the .jshover class to any element you want hover css effects on. In your css, add rules like this:

ul li:hover, ul li.over { rules here }

这篇关于使用jQuery.support检测IE6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆