有些CSS无法通过W3C标准,但又非常需要使用的时候,
例如做透明效果滤镜时会用到这两段,
filter:progid:DXImageTransform.Microsoft.Alpha(opacity=40);
-moz-opacity: 0.4;
第一行是IE滤镜,可以使用条件批注的方式
第二行-moz-opacity: 0.4;是给Mozilla Firefox浏览器的样式
就不适合用条件批注,若直接写在CSS中就无法通过检测
如此就可以使用这方法将样式写到JS档案中
写法例如:
<script type="text/javascript">
document.writeln("<style type=\"text\/css\">");
document.writeln("<!--");
document.writeln(".opacityit img {");
document.writeln("-moz-opacity: 0.4;");
document.writeln("}");
document.writeln("-->");
document.writeln("<\/style>")
</script>
 
这样一来不但可以使用,也不怕css无法通过w3c的标准检测(像是在作弊)
您可以在网络搜寻html转换js的小工具,转换就更方便了