这个注释/ * @ cc_on!@ * / 0在javascript中的if语句中做了什么? [英] what does this comment /*@cc_on!@*/0 do inside an if statement in javascript?

查看:383
本文介绍了这个注释/ * @ cc_on!@ * / 0在javascript中的if语句中做了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于我在电子书上发现的关于HTML5的评论只是一个小问题:
/ * @ cc_on!@ * / 0 这个评论应该以某种方式绑定到IE的识别浏览器为了使用document.createElement()来创建无法识别的HTML5元素,但是我没有找到有关其工作原理的有用信息,即使作者也没有解释它。有人可以解释一下它是什么以及它做了什么吗?

just a little question about this comment I found on an ebook about HTML5: /*@cc_on!@*/0 this comment should be somehow bound to the recognition of the IE browser in order to use the document.createElement() to create the unrecognized HTML5 elements, but I didn't find useful infos about the meaning of how this works cause even the author doesn't explain it. Could someone explain me what it is and what it does, please?

感谢您的关注!

编辑:

在电子书中作者说:

下一个示例演示如何解决HTML5中引入的所有新元素的问题。在这里,我们包含了我们要强制IE识别的所有元素:

The next example demonstrates how to solve the problem for all the new elements introduced in HTML5. Here we include all the elements we’d like to force IE to recognize:

以下是代码:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <title>Styling Unknown Elements - 3</title>
    <script>
        (function() {
            if (! /*@cc_on!@*/ 0)
                return;

            var e = "abbr,article,aside,audio,canvas,  datalist,details,eventsource,figure,footer,header,hgroup,mark,menu,meter,nav,output, progress,section,time,video".split(','),
                i = e.length;
            while (i--) {
                document.createElement(e[i]);

            }
        })()
    </script>
    <style>
        time {
            font-style: italic;
        }
    </style>
      ...

对于可怕的缩进感到抱歉,但我正在使用平板电脑。无论如何,请看看脚本标签和if条件。

Sorry for the horrible indentation but I am using a tablet. Anyway please take a look at the script tag and at that if condition.

推荐答案

@cc_on声明 IE的条件编译标志(< 11)浏览器

@cc_on Statement is the conditional compilation flag for IE(< 11) browser

来自 MSDN

@cc_on语句(JavaScript)


在脚本中的注释中激活条件编译支持。

Activates conditional compilation support within comments in a script.

小心


Internet Explorer 11
标准模式和Windows应用商店应用不支持条件编译。 Internet Explorer 10标准模式和所有早期
版本支持条件编译

Conditional compilation is not supported in Internet Explorer 11 Standards mode and Windows Store apps. Conditional compilation is supported in Internet Explorer 10 Standards mode and in all earlier versions.



/*@cc_on @*/
/*@
    document.write("JavaScript version: " + @_jscript_version + ".");
    document.write("<br />");
    @if (@_win32)
        document.write("Running on the 32-bit version of Windows.");
    @elif (@_win16)
        document.write("Running on the 16-bit version of Windows.");
    @else
        document.write("Running on a different operating system.");
    @end
@*/

so

if(!/*@cc_on!@*/0)

如果您的浏览器不知道条件编译( IE < 11除外),则表达式为:

If your browser doesn't know conditional compilation (other than IE < 11), the expression will be:

if(!0) // ==> TRUE

否则它将是:

if(!!0) // ==> FALSE

这篇关于这个注释/ * @ cc_on!@ * / 0在javascript中的if语句中做了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆