#Region ... #endRegion
的代码块,可以折叠显示。HTML中是否有类似的功能?目前我只是在HTML页面上使用注释来标记不同元素的位置,但我希望有一个单一的折叠点,而不是所有的
<tr>
、<td>
和 <div>
标签都被折叠显示。这确实取决于集成开发环境,我今天刚注意到Visual Studio的免费Web Essentials 2012插件的最新版本已经在HTML中添加了“区域”支持。
http://visualstudiogallery.msdn.microsoft.com/07d54d12-7133-4e15-becb-6f451ea3bea6
http://vswebessentials.com/changelog
<!--#region main -->
<!--#endregion -->
As of Visual Studio 2013 Update 4 regions are now supported in the HTML editor. You may use the built in code snippet: type "
<!-- #region SampleRegion -->
<!-- #endregion -->
You can find the details of this improvement and other new features in update 4 here.
我的看法是不可以。
Region只是一个IDE指令,在编辑器(Visual Studio)中才会被识别。在HTML标准中没有任何内容,而且无论您在HTML中放置什么内容,它都会直接发送到浏览器,因此我从未遇到过任何情况,并且无法想象以后会有类似的情况出现。
选中你想要折叠的部分,然后前往 Edit -> Outlining -> Hide Selection
参考资料: 如何在Visual Web Developer中折叠和展开HTML元素
注: 假设您正在使用Visual Studio
对于HTML:
<!--#region -->
Code code code...
<!--#endregion -->
Javascript的相关内容:
// #region
Code code code...
// #endregion
<!-- -->
是注释符号。//
是注释符号。为了使 Visual Studio 2019 中的轮廓功能正常工作,请确保在注释结束标记前后留有空格:
<!-- #region -->
<!--Blazor Components Signal-R server-->
<script src="_framework/blazor.server.js"></script>
<!-- jQuery -->
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<!-- jQuery UI 1.11.4 -->
<script src="~/lib/plugins/jquery-ui/jquery-ui.min.js"></script>
<!--Bootstrap bundle-->
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<!-- #endregion -->
注意:这个功能在Visual Studio 2022
中还不能使用。
<div>
Code Blocks...
</div>
在我学习之前
<!--#region explanation blocks -->
Code Blocks...
<!--#endregion -->
它们两个都解决了问题。
<!-- Your comment caption -->
<div class="hidden">
Put Your comments here
</div>
<!-- #region -->
...
Code
...
<!-- #endregion -->
#
和region
或endregion
之间没有空格。奇怪的是,有时候在Visual Studio 2022中区域功能对我有效,有时候则无法使用。我尝试了上面很多方法,但是要么区域实际上被创建了,要么就没有。
但是我发现这种方法每次都能行:
<div data-region="My Header Region">This is my Header Region</div>
</div>
**由于@AndrewMorton的评论进行了更新。
<div>
层似乎是一个不好的想法。 - Andrew Morton
<!-- region 区域名称 -->
和<!-- endregion -->
在Intellij中起作用。 - Hisham Bawa