如何使用jQuery可能使用jQuery.browser检测IE7?
如何使用jQuery可能使用jQuery.browser检测IE7?
请参阅 $.browser。这个特性已经被弃用,您应该考虑使用$.support。
回答问题,这是一种非常可靠的技术,主要用于样式表,但也可以轻松用于检查浏览器版本,或者最好作为选择器的一部分。
使用以下标记(来自HTML5 Boilerplate):
<!--[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]-->
<head>
在jQuery中使用hasClass选择器
$('html').hasClass('ie7');
$('html.ie7 .myclass').dostuff();
并将其作为CSS中正常选择器的一部分使用
.mydiv {max-height:50px}
.ie6 .mydiv {height:50px} /* ie6 max-height fix */
综合考虑其他因素:
if ($.browser.msie && $.browser.version == 7) {
//do something
};
应该可以工作。然而这是否是正确的做法就是另一个问题了。