【问题标题】:How to detect IE11 in wordpress and change css with if statement?如何在 wordpress 中检测 IE11 并使用 if 语句更改 css?
【发布时间】:2014-01-12 12:17:51
【问题描述】:

我想知道如何检测 IE11 并将 css 更改为通过 Jquery 或 <style type="text/css"> 进行调试

条件语句不起作用<!--[if IE 11]-->...somecode...<![endif]-->,jquery 也不是。 :(

喜欢

<script type="text/javascript">
  if(//IE11){
    <style>
    #sms-cont {
    height:315px;
    }
    </style>
   }
</script>

或通过

   if(//IE11) {
    $(document).ready(function () {
    $("#sms-cont").css({
        "width": "385px",
        "height": "315px"
      });
   });
  }       

知道如何检测它真正起作用并更改任何代码或将 css 用于调试吗?

【问题讨论】:

标签: jquery css wordpress internet-explorer-11


【解决方案1】:

借助下面的代码,您可以根据不同版本的 IE 获得不同的类。

<!--[if lt IE 8]> <html class="ie7 oldie"> <![endif]-->
<!--[if IE 8]>    <html class="ie8 oldie"> <![endif]-->
<!--[if IE 9]>    <html class="ie9 oldie"> <![endif]-->
<!--[if gt IE 10]><html class="ie11 oldie"> <![endif]-->
<html class="">
<!--<![endif]-->

【讨论】:

  • 有人能帮我解决这个问题吗?(???所有这些条件都不起作用,因为我说 jquery 也不是,我使用的是 wordpress 3.8。
  • @Mr.beginner - 理想的解决方案是了解您为什么需要 IE 检测,然后从那里找到不需要任何浏览器检测的解决方案。 IE11 实际上非常适合现代 Web 标准,因此几乎不需要检测它。不幸的是,您向我们展示的代码没有为我们提供足够的信息来理解您为什么要检测 IE11。如果您在问题中向我们提供更多信息,我们也许可以为您提供替代解决方案。
【解决方案2】:

您可以使用http://whichbrowser.net/等解决方案

【讨论】:

  • 它显示了真实信息,但是如何将它与我的代码中提到的 if 语句一起使用?
【解决方案3】:

我刚刚找到了我自己的问题的答案。 这是解决方案

    if(navigator.userAgent.match(/Trident.*rv:11\./)) {

 $(document).ready(function(){
    //some code stuff goes here
  }); 
 }

毫无疑问,它的 100% 有效。 注意:在这之间的代码中你可以放 jquery 或 javascript 代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    • 2023-01-22
    相关资源
    最近更新 更多