HTML 注释语言javascript,css 详细细节

不少人应该也和我同样遇到过这样的问题,须要去判断浏览器版本或则在javascript 里面去作复杂的逻辑处理来按需加载咱们的js,css.javascript

不过html 自带的这一注释标记子认为人有用,或许这本是入门级的知识了,翻出来看看也不错。css

下面就是IE中的HTML条件注释的样子,注意它使用的结束分隔符的技巧。html

<!--[if IE]> 
This content is actually inside an HTML comment. 
It will only be displayed in IE. 
<![endif]--> 
<!--[if gte IE 6]> 
This content will 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.java

Conditional comments are also supported by IE's Javascript interpreter, and C and C++ programmers may find them similar to the #ifdef/#endif functionality of the C preprocessor. A Javascript conditional comment in IE begins with the text /*@cc_on and ends with the text @*/. (The cc in cc_on stands for conditional compilation.) The following conditional comment includes code that is executed only in IE:程序员

IE的Javascript解析器也支持条件注释,C和C++程序员可能会以为它们和C处理器的 #ifdef/#endif 功能很相似。Javascript条件注释使用字符/*@cc_on标记开始,用 @*/标记结束。
web

/*@cc_on浏览器

   @if (@_jscript)ide

     // This code is inside a JS comment but is executed in IE.this

     alert("In IE");spa

   @end

   @*/

Inside a conditional comment, the keywords @if @else , and @end delimit the code that is to be conditionally executed by IE's Javascript interpreter. Most of the time, you need only the simple conditional shown above: @if (@_jscript) . Jscript is Microsoft's name for its Javascript interpreter, and the @_jscript variable is always true in IE. 

在条件注释内部,关键字 @if @else @end 区划出哪些是要被IE的Javascript解析器条件执行的。大多数时候,只须要上面所示的简单条件: @if (@_jscript) .Jscript是微软本身的Javascript解析器的名字, @_jscript 变量在IE中的值恒为ture

With clever interleaving of conditional comments and regular Javascript comments, you can set up one block of code to run in IE and a different block to run in all other browsers:

经过条件注释和常规的Javascript注释的合理交叉结合,能够设置让IE和其它浏览器运行不一样的代码。

/*@cc_on

   @if (@_jscript)

     // 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 
     // except IE will run this code. 
     alert('You are not using Internet Explorer');

/*@end

   @*/

Conditional comments, in both their HTML and Javascript forms, are completely nonstandard. They are sometimes a useful way to achieve compatibility with IE, however.

包括HTML形式和Javascript形式中的条件注释,都是彻底非标准的,但它们有时是兼容IE的颇有用的方式。

相关文章
相关标签/搜索