如果浏览器低于 IE9,我想在 jQuery 中执行某个代码。是的,我已经知道
<!--[if ... IE ]> <![endif]-->
但我想要的是在 scipt 标签内检查这个条件并使用 jQuery document.ready
<script>
$(document).ready(function(){
//code to check if lt ie9
});
</script>
最佳答案
您可以通过 <html>
上的类定位较旧的 Internet Explorer 版本 (<= 9)元素...
<!--[if lt IE 7]> <html class="ie ie6 lte9 lte8 lte7"> <![endif]-->
<!--[if IE 7]> <html class="ie ie7 lte9 lte8 lte7"> <![endif]-->
<!--[if IE 8]> <html class="ie ie8 lte9 lte8"> <![endif]-->
<!--[if IE 9]> <html class="ie ie9 lte9"> <![endif]-->
<!--[if gt IE 9]> <html> <![endif]-->
<!--[if !IE]><!--> <html> <!--<![endif]-->
... 然后检查是否 <html>
有课.lt9
或 .lt8
— 无论您的目标是什么版本的 Internet Explorer:
if($('html').hasClass('lte9')) { /* LTE IE9 */ }
但是,我建议使用 Modernizr功能检测而不是检查特定浏览器。
关于javascript - 如果浏览器 lt ie9 执行某些 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18145816/