为什么非Javascript浏览器中的这个Javascript代码有额外的评论? [英] Why does this Javascript code inside a non-Javascript browser have extra commenting?

查看:79
本文介绍了为什么非Javascript浏览器中的这个Javascript代码有额外的评论?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 没有与W3有关。在人们开始抱怨之前,他们的教程非常糟糕,他们混淆的名字意味着他们以某种方式连接到W3,但实际上他们并没有。

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屋!

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