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)

转载于:https://www.cnblogs.com/qingqingcai/p/3357393.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值