如何在wordpress中检测IE11并用if语句更改css?

时间:2013-12-24 08:54:27

标签: jquery css wordpress internet-explorer-11

我想知道如何通过Jquery或<style type="text/css">

检测IE11并将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调试?

3 个答案:

答案 0 :(得分:0)

您可以使用http://whichbrowser.net/

等解决方案

答案 1 :(得分:0)

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

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

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

毫无疑问,它的100%工作。 注意:在代码之间可以放置jquery或javascript代码。

答案 2 :(得分:-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]-->