[Java教程]HTML条件注释与JavaScript条件注释
0
2013-10-08 17:00:08
HTML条件注释和javascript条件注释
条件注释主要是针对ie的不兼容性,通过条件注释实现以某种方式为ie编写代码,而按照另一种方式为其他浏览器编写代码。条件注释并不符合标准规范,但在处理不兼容性事非常有用。
HTML条件注释
html条件注释,经测试能被ie以外的浏览器识别,输出结果与预想一致。
This is normal HTML content,but IE will not display it because of
the comment above and the comment below.
This is normal content,displayed by all browsers.
javascript条件注释
Javascript条件注释只被ie中JavaScript解释器支持。
/*@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
@*/
(以上案例参考Java权威指南Page 332)
本文网址:http://www.shaoqun.com/a/72037.html
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:admin@shaoqun.com。
JavaScript
0