zoukankan      html  css  js  c++  java
  • HTML条件注释与JavaScript条件注释

    一、HTML条件注释和javascript条件注释说明

    条件注释主要是针对ie的不兼容性,通过条件注释实现以某种方式为ie编写代码,而按照另一种方式为其他浏览器编写代码。条件注释并不符合标准规范,但在处理不兼容性事非常有用。

    二、HTML条件注释

    html条件注释,经测试能被ie以外的浏览器识别,输出结果与预想一致。

    举个栗子:

    <!--[if IE]>
    This content is actually inside an HTML comment.
    It will only be displayed in IE.
    <![endif]-->

    <!--[if IE6]>
    This content is actually only be displayed by IE 6 and later.
    <![endif]-->

    <!--[if !IE]><-->
    This is normal HTML content,but IE will not display it because of
    the comment above and the comment below.
    <!--><![endif]-->

    This is normal content,displayed by all browsers.

    三、javascript条件注释

    Javascript条件注释只被ie中JavaScript解释器支持。

    举个栗子:
    <script>
    /*@cc_on

     @if(@_jscript)
      //This code is inside a JS comment but is executed in IE.
      //This code is inside a conditional comment,which is also a 
      //regular Javascript comment.IE runs it but other browsers ignore it.
      alert("You are using Internet Explorer");
     @else*/
      //This code is no longer inside a Javascript comment,but is still
      //inside the IE conditional comment. This means that all browsers
      //excepte IE will run this code.
      alert("you are not using Internet Explorer");
     /*@end
     @*/
     </script>

    (以上案例参考Java权威指南Page 332)

  • 相关阅读:
    四则运算结对作业
    读《构建之法》第四、十七章有感
    四则运算练习的命令行软件
    Spring01
    oop01
    运行shell脚本的三种方式
    正则表达式的基础组成部分
    C语言文件函数
    shell文件描述符及重定向
    shell基础
  • 原文地址:https://www.cnblogs.com/qingqingcai/p/3357393.html
Copyright © 2011-2022 走看看