为什么非Javascript浏览器中的这个Javascript代码有额外的评论? [英] Why does this Javascript code inside a non-Javascript browser have extra commenting?
问题描述
在 W3教程上,它显示了htis代码:
On the W3 tutorial, it shows htis code:
<html>
<body>
<script type="text/javascript">
<!--
document.getElementById("demo").innerHTML=Date();
//-->
</script>
</body>
</html>
然后它说:
注释行(//)末尾的两个正斜杠是
JavaScript注释符号。这可以防止JavaScript执行
- >标记。
The two forward slashes at the end of comment line (//) is the JavaScript comment symbol. This prevents JavaScript from executing the --> tag.
这对我没有意义。我以为整件事都被评论了。
This doesn't make sense to me. I thought the whole thing got commented out.
推荐答案
首先,W3Schools
First of all, W3Schools has nothing to do with W3. Their tutorials were pretty horrible before people started complaining and their confusing name implies that they are somehow connected to W3, but in reality they aren't.
其次,这个不再需要方法。没有使用过的浏览器不干净地支持JS( links
, lynx
等等,JS没有麻烦任何代码。)
Second of all, this method is not needed anymore. There are no used browsers that don't support JS cleanly (links
, lynx
, etc. have no troubles with JS code whatsoever).
话虽这么说,代码应该这样做:
That being said, the code is supposed to do this:
<!--
I am a HTML comment
-->
<!--
If I am placed in a JS block, the web browser should ignore me
alert('and me');
-->
<!--
If you comment out the HTML comment ending tag, apparently
the browser will treat the comment as JS code *only*
if the browser supports JS.
//-->
这篇关于为什么非Javascript浏览器中的这个Javascript代码有额外的评论?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!