html/javascript/css 注释表达式详解

本文提供了针对IE浏览器的HTML、JS及CSS兼容性问题的多种解决办法,包括使用条件注释、编译注释和特定前缀等技术手段。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

浏览器之间的兼容是个问题,而IE的兼容性尤其严重。下面是我搜集的一些处理html/js/css兼容性问题的好方法。

html 条件注释
<html>
<body>
<!--[if IE]>
根据条件判断,这是Internet Explorer<br />
<![endif]-->
<!--[if IE 5]>
根据条件判断,这是Internet Explorer 5<br />
<![endif]-->
<!--[if IE 5.0]>
根据条件判断,这是Internet Explorer 5.0<br />
<![endif]-->
<!--[if IE 5.5]>
根据条件判断,这是Internet Explorer 5.5<br />
<![endif]-->
<!--[if IE 6]>
根据条件判断,这是Internet Explorer 6<br />
<![endif]-->
<!--[if gte IE 5]>
根据条件判断,这是Internet Explorer 5 或者更高<br />
<![endif]-->
<!--[if lt IE 6]>
根据条件判断,这是版小于6的Internet Explorer<br />
<![endif]-->
<!--[if lte IE 5.5]>
根据条件判断,这是Internet Explorer 5.5或更低<br />
<![endif]-->
</body>
</html>


javascript 编译注释
[quote]<script type="text/javascript">
/*@cc_on
document.write('IE 4+ browser support @cc_on<br>');
/*@if (@_jscript_version >= 5)
document.write("IE Browser that supports JScript 5+<br>");
@elif (@_jscript_version >= 4)
document.write("IE Browser that supports JScript 4+<br>");
@else @*/
document.write("Non IE Browser or lower version IE<br>");
/*@end
@*/
</script>[/quote]

javascript编译常量
[url]http://www.javascriptkit.com/javatutors/conditionalcompile2.shtml[/url]

css !important.
!importan 在firefox,ie7中支持,在ie6中不支持。
[quote]<div style="color: red !important; color: blue;">
IE7,firefox中显示为红色文字,IE6中显示为蓝色文字
</div>
[/quote]

ie6支持 * html 前缀 ,ie7 支持 *+html 前缀,firefox不支持。
ie支持css expression,在firefox中是不支持的。
[quote]
#testcss {/*any*/
background-color:red;
}
* html #testcss {/*ie6*/
background-color:green;
}
*+html #testcss {/*ie7*/
background-color:yellow;
}[/quote]


测试文件见附件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值