简体   繁体   English

这些评论之间有什么区别

[英]What is the difference between these comments

What is the difference between these types of comments in ASP.NET's ASPX markup page? ASP.NET的ASPX标记页面中这些类型的注释有什么区别?

<%-- something here --%>

and the html comment 和HTML评论

<!-- something here -->

The first you will only see in the ASPX and not the rendered HTML Page 第一个只能在ASPX中看到而不是渲染的HTML页面

The second will be rendered as part of the HTML 第二个将呈现为HTML的一部分

The first is a server side comment. 第一个是服务器端评论。 It will stop the .NET code from executing. 它将阻止.NET代码执行。

The second is plain HTML comments. 第二个是纯HTML注释。 The .NET code inside the comments will still be executed on the server-side but the resulting markup will be commented out to the browser. 注释中的.NET代码仍将在服务器端执行,但生成的标记将被注释掉到浏览器中。

Scott Guthrie has a short but sweet blog post covering the differences a little more: 斯科特格思里(Scott Guthrie)有一篇简短而又甜蜜的博文,内容更多:

Tip/Trick: Using Server Side Comments with ASP.NET 提示/技巧:在ASP.NET中使用服务器端注释

The <% ... %> comment is a so called server-side comment (and will not be shown in the final output). <% ... %>注释是所谓的服务器端注释(并且不会显示在最终输出中)。 <!-- ... --> is a regular HTML comment (and will be shown in the browser by viewing the source). <!-- ... -->是常规HTML注释(将通过查看源在浏览器中显示)。

The key difference is that with client-side comments it is the browser which is ignoring the content within them. 关键的区别在于,对于客户端注释,浏览器忽略了其中的内容 Code/controls within client-side comments will still be executed on the server and sent down to the browser. 客户端注释中的代码/控件仍将在服务器上执行并发送到浏览器。 As such, if there is a server error caused within them it will block running the page. 因此,如果在其中导致服务器错误,它将阻止运行页面。

Read more about the differences here: Using Server Side Comments with ASP.NET 2.0 在此处阅读有关差异的更多信息: 在ASP.NET 2.0中使用服务器端注释

the first one would not appear in the final HTML output. 第一个不会出现在最终的HTML输出中。 the second one is how you comment in HTML and it will appear in the HTML output. 第二个是你如何在HTML中发表评论,它将出现在HTML输出中。

This is a server side comment and will not appear in the HTML markup: 这是服务器端注释,不会出现在HTML标记中:

<%-- something here --%>

This is an HTML comment and will appear in the HTML markup, as it is part of it: 这是一个HTML注释, 出现在HTML标记中,因为它是其中的一部分:

<!-- something here -->

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

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