简体   繁体   English

条件注释不适用于IE-9

[英]Conditional Comments not working on IE-9

I have a page, where I need to show help text based on the version of the IE. 我有一个页面,需要在该页面上显示基于IE版本的帮助文本。 I have decided to use conditional comments as per this blog . 我已决定根据此博客使用条件注释。 My html page looks like this ... 我的html页面看起来像这样...

<!DOCTYPE html>
<html>
   <head>
        <title>Application Title</title>
        <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    </head>
  <!--[if lt IE 9 ]><body style="margin: 0px;" class="ie9lt"><![endif]-->
  <!--[if IE]> <body style="margin: 0px;" class="ie9"> <![endif]-->
  <!--[if (gt IE 10)|!(IE)]>-->
  <body style="margin: 0px;"><!--<![endif]-->
        <div id="id1">
        ....
        ....
</html>

I have opened this file on IE 9 but checked the html by inspect the elements option but my body element didn't have ie9 class (for that matter no class) associated with it. 我已经在IE 9上打开了该文件,但是通过检查elements选项检查了html,但是我的body元素没有与之关联的ie9类(因此没有任何类)。 Am I missing something here? 我在这里想念什么吗? Please help 请帮忙

I've checked your HTML with IE9 and it works perfectly fine. 我已经用IE9检查了您的HTML,它工作得很好。 I can see that body has ie9 class. 我可以看到该body具有ie9类。

Can you see the same in HTML inspector as below? 您可以在HTML检查器中看到以下内容吗? Also, is your browser mode set to IE9? 另外,您的浏览器模式是否设置为IE9?

IE9

Sometimes, when you have errors in your HTML document IE automatically switches to Compatibility View mode and then your body class is ie9lt (and not ie9 ). 有时,当您的HTML文档中有错误时,IE会自动切换到“ 兼容性视图”模式,然后您的body类为ie9lt (而不是ie9 )。

you can try to be more specific en work on the root HTML tag: 您可以尝试在根HTML标记上进行更具体的操作:

<!doctype html>
<!--[if IE 7 ]><html lang="en" class="ie7"><![endif]-->
<!--[if IE 8 ]><html lang="en" class="ie8"><![endif]-->
<!--[if IE 9 ]><html lang="en" class="ie9"><![endif]-->
<!--[if (gt IE 9)|!(IE)]><!-->
<html lang="en">
<!--<![endif]-->

I'd only put style definitions in those comments, nothing else. 我只会在这些注释中添加样式定义,仅此而已。 Let the html document stay as clean as possible. 让html文档保持尽可能干净。 That's probably one of the most messy implementations of that hack there is. 那可能是该黑客​​最混乱的实现之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM