根据标题; 是否可以在有效的HTML中嵌套注释?看下面的例子......
<p>some text</p>
<!-- comment 1
<p>commented out html</p>
<!-- comment 2
// are nested html comment allowed?
end of comment 2 -->
<p>more commented out html</p>
end of comment 1 -->
<p>some more text</p>
Run Code Online (Sandbox Code Playgroud)
看来不是,有人知道如何让嵌套注释工作吗?
我用来HtmlTextWriter将 html 输出到流中。但是,我缺少一种编写 html 注释的方法。当然,我可以编写一个扩展方法
public static void WriteComment(this HtmlTextWriter writer, string comment)
{
writer.Write("<!-- ");
writer.WriteEncodedText(comment);
writer.Write(" -->");
}
Run Code Online (Sandbox Code Playgroud)
但这确实感觉有点不优雅——是否有一些我没有看到的内置方法?