如何使用注释使 HTML 代码处于非活动状态

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4393699/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 05:39:00  来源:igfitidea点击:

How to make HTML code inactive with comments

htmlxhtml

提问by Quazi

I have some HTML code on a page that I don't want to erase, but make inactive for the short term. How can I make the browser ignore parts of the page in the same way the //works in some programming languages?

我在页面上有一些 HTML 代码,我不想删除这些代码,但在短期内使其处于非活动状态。如何让浏览器以与//某些编程语言的工作方式相同的方式忽略页面的某些部分?

回答by deceze

Behold HTML comments:

看 HTML 注释:

<!-- comment -->

http://www.w3.org/TR/html401/intro/sgmltut.html#idx-HTML

http://www.w3.org/TR/html401/intro/sgmltut.html#idx-HTML

The proper way to delete code without deleting it, of course, is to use version control, which enables you to resurrect old code from the past. Don't get into the habit of accumulating commented-out code in your pages, it's no fun. :)

删除代码而不删除它的正确方法当然是使用版本控制,它使您能够从过去复活旧代码。不要养成在页面中积累注释掉的代码的习惯,这很不好玩。:)

回答by Ahsan Khurshid

HTML Comments:

HTML 注释:

<!-- <div> This div will not show </div> -->

See Reference

见参考

CSS Comments:

CSS 评论:

/* This style will not apply */

See Reference

见参考

JavaScript Comments:

JavaScript 评论:

// This single line JavaScript code will not execute

OR

或者

/*
   The whole block of JavaScript code will not execute
*/

See Reference

见参考

回答by guido

To comment block with nested comments: substitute inner (block) comments from "--" to "++"

使用嵌套注释来注释块:将内部(块)注释从“--”替换为“++”

<!-- *********************************************************************
     * IMPORTANT: To uncomment section
     *            sub inner comments "++" -> "--" & remove this comment
     *********************************************************************
<head>
   <title>My document's title</title> <++! My document's title ++>
   <link rel=stylesheet href="mydoc.css" type="text/css">
</head>

<body>
<++! My document's important HTML stuff ++>
...
...
...
</body>

*********************************************************************
* IMPORTANT: To uncomment section
*            sub inner comments "++" -> "--" & remove this comment
*********************************************************************
-->

Thus, the outer most comment ignores all "invalid" inner (block) comments.

因此,最外面的评论会忽略所有“无效”的内部(块)评论。

回答by user2875181

Just create a multi-line comment around it. When you want it back, just erase the comment tags.

只需在它周围创建一个多行注释。当你想要它回来时,只需擦除评论标签。

For example, <!-- Stuff to comment out or make inactive -->

例如, <!-- Stuff to comment out or make inactive -->

回答by RAN

Use:

用:

<!-- This is a comment for an HTML page and it will not display in the browser -->

For more information, I think 3 On SGML and HTMLmay help you.

有关更多信息,我认为3 On SGML 和 HTML可能对您有所帮助。

回答by Janarthanan Ramu

If you are using Eclipsethen the keyboard shortcut is Ctrl+ Shift+ /to add a group of code. To make a comment line or select the code, right click -> Source-> Add Block Comment.

如果你使用的Eclipse那么键盘快捷键为Ctrl+ Shift+/中添加的代码组。要创建注释行或选择代码,请右键单击 ->->添加块注释

To remove the block comment, Ctrl+ Shift+ \or right click -> Source-> Remove Block comment.

要删除块注释,Ctrl+ Shift+\或右键- >来源- >删除块注释

回答by Ferrakkem Bhuiyan

Reason of comments:

评论原因:

  1. Comment out elements temporarily rather than removing them, especially if they've been left unfinished.
  2. Write notes or reminders to yourself inside your actual HTML documents.
  3. Create notes for other scripting languages like JavaScript which requires them
  1. 暂时注释掉元素而不是删除它们,特别是如果它们尚未完成。
  2. 在实际的 HTML 文档中给自己写笔记或提醒。
  3. 为需要它们的其他脚本语言(如 JavaScript)创建注释

HTML Comments

HTML 注释

<!-- Everything is invisible  -->