gpt4 book ai didi

javascript - 如果浏览器 lt ie9 执行某些 javascript

转载 作者:数据小太阳 更新时间:2023-10-29 04:59:16 26 4
gpt4 key购买 nike

如果浏览器低于 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com