简体   繁体   English

是什么 <!— //--> 在ASP中意味着什么?

[英]What does <!— //--> mean in ASP?

<script language="javascript">
    <!--    
             //some logic here 
    //-->
</script>

What does <!-- //--> mean? <!-- //-->是什么意思? . I thought they were comment, however, the double slash before --> puzzles me. 我以为他们是评论,但是->之前的双斜线使我感到困惑。

That has nothing to do with ASP. 这与ASP无关。 That's a historical artifact from when Javascript was new and not supported in all browsers. 这是Java出现时的历史产物,并非所有浏览器都支持Javascript。 <!-- is a legitimate component of the JS language itself, and is treated as a "do nothing" command. <!--是JS语言本身的合法组成部分,被视为“不执行任何操作”命令。 --> however, is NOT part of JS, so you have to escape it using a proper JS comment, hence //--> -->但是,它不是 JS的一部分,因此您必须使用适当的JS注释对其进行转义,因此//-->

All this is just to hide the JS code from stoneage/obsolete browsers which didn't understand the <script> tag. 所有这些只是在无法理解<script>标记的旧版/过时浏览器中隐藏JS代码。 Remember that browsers ignore tags which they don't recognize. 请记住,浏览器会忽略无法识别的标签。 A non-JS browser would skip over <script> and start outputting the JS code as text. 非JS浏览器将跳过<script>并开始将JS代码输出为文本。 Hence the comment sequence. 因此,评论顺序。 Even if the browser doesn't understand <script> and </script> it WILL understand an HTML comment, and skip over all of the code. 即使浏览器不理解<script></script>它也将理解HTML注释,并跳过所有代码。

Eg if you loaded a modern JS-enabled page in Netscape 1.0 and had something like: 例如,如果您在Netscape 1.0中加载了启用了现代JS的页面,并且具有以下内容:

<script>
  alert('hello, world!');
</script>
<foo>
  Hello again
</foo>

Then you wouldn't get an alert, you'd actually see 然后您不会收到警报,您实际上会看到

alert('hello, world!');Hello again

in the browser window. 在浏览器窗口中。 But if you had 但是如果你有

<script>
<!--
   alert('hello, world!');
//-->
</script>
<foo>
   Hello again
</foo>

then you'd only see 那你只会看到

 Hello again

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM