如何使用jQuery.support检测IE7和更低? [英] How to detect IE7 and lower using jQuery.support?

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

问题描述

目前我正在使用jQuery.browser来检测IE7并降低

Currently I'm using jQuery.browser to detect IE7 and lower

if ($.browser.msie && parseInt($.browser.version) <= 7) {
    //codes
}

但是在jQuery 1.3中不推荐使用jQuery.browser并在jQuery 1.9中删除了,我从jQuery网站上读到我们应该使用特征检测(jQuery.support)。

but jQuery.browser was deprecated in jQuery 1.3 and removed in jQuery 1.9, I read from jQuery website that we should use feature detection instead (jQuery.support).

那么,如何使用jQuery.support检测IE7和更低?

So, how to detect IE7 and lower using jQuery.support?

推荐答案

最好的方法是使用条件注释并使用jQuery的 hasClass()进行检查。

The best way is to use conditional comments and check it using jQuery's hasClass().

<!--[if lt IE 7]>      <html class="ie6"> <![endif]-->
<!--[if IE 7]>         <html class="ie7"> <![endif]-->
<!--[if IE 8]>         <html class="ie8"> <![endif]-->
<!--[if gt IE 8]><!--> <html>         <!--<![endif]-->

在你的jQuery中,检查IE 7:

And in your jQuery, check for IE 7:

// Check IE 7
if ($('html').hasClass('ie7');

无论如何,这种方法都不能被欺骗。另见:条件样式表

This method cannot be spoofed no matter what. Also see: Conditional Stylesheets by Paul Irish.

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

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