关于我在一本关于 HTML5 的电子书上找到的评论的一个小问题: /*@cc_on!@*/0 这个评论应该以某种方式绑定(bind)到 IE 浏览器的识别,以便使用 document.createElement() 来创建无法识别的 HTML5 元素,但我没有找不到有关其工作原理含义的有用信息,因为即使作者也没有解释它。有人可以向我解释一下它是什么以及它的作用吗?
感谢关注!
编辑:
作者在电子书中说:
下一个示例演示如何解决 HTML5 中引入的所有新元素的问题。这里我们包含了所有我们想要强制 IE 识别的元素:
代码如下:
<!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 条件。
最佳答案
@cc_on语句是IE
(<11)浏览器的条件编译标志
引自 MSDN
@cc_on 语句(JavaScript)
Activates conditional compilation support within comments in a script.
注意
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
@*/
所以
if(!/*@cc_on!@*/0)
如果您的浏览器不支持条件编译(IE
< 11 除外),则表达式为:
if(!0) // ==> TRUE
否则会是:
if(!!0) // ==> FALSE
关于javascript - 这个 comment/*@cc_on!@*/0 在 javascript 的 if 语句中做什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24473882/