可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
What's the equivalent of <%-- --%>
in ASP Classic?
I have to modify a legacy ASP application and I'd like to comment out a block of HTML:
<td>
some table cell I'd like to comment out, including
some <%= inlineServerSideVBScriptExpressions() %>
</td>
Wrapping everything in <%-- ... --%>
, as I'd do in ASP.NET, doesn't work and results in the compilation error "Expected statement". HTML comments <!-- ... -->
are not an option either, since the inline ASP expressions would get evaluated and fail.
回答1:
There's no "built-in" way to do block comments in ASP Classic. You have to put a '
before each line you don't want to run.
回答2:
Try this:-
<!-- METADATA
Your comments here
-->
The METADATA
indicates to the ASP processor that this is a comment that does not need to be sent to the client.
回答3:
Apostrophe-style comments are supported in VBScript. They might work here.
These are removed when the script is processed, and aren't sent to the browser.
<%
'This line and the following two are comments.
'The function below does something ineluctable.
'So don't mess with it.
SomeFunction()
%>
Here is a source for this.
回答4:
Here is how I can easily comment out an entire block of mixed code:
<% If False Then %>
<html stuff></html stuff>
<% more asp stuff %>
<% End If %>
If I had to do this many times I would make some kind of macro for my computer to do this via hotkey.
回答5:
This is what source control is for. Just delete the code and mark it appropriately when you check it in so you can find the snippet later if you need it.
回答6:
@Heinzi: Since you can't use Joel Coehoorn's excellent solution, you could also use something like
<%
Dim blnDebug : blnDebug = True
If NOT blnDebug Then
' Display mixed HTML/ASP code
%>
HTML, HTML .. <%=someASPfunction() %> .. more HTML
<%
End If
%>
...and then hack away at the file and when you're ready to turn on the code you've effectively "commented out", just set blnDebug
to False
. It beats putting apostrophes in front of every in-line code call for me.
回答7:
I know that you can do that in Dreamweaver; I saw my colleague doing it.
But I am using Visual Studio or Notepad++ most of time, and this feature is not working there.
So I am commenting multiple lines using special pasting of a single quote, '
, by pressing:
Shift + Alt + arrow down or up, then adding a single quote, '
.
And the same for uncommenting the '
by selecting all '
s in all lines and then delete.
回答8:
The way I always comment out is using:
<%'=Var%>
回答9:
Another way to block comment your code is to escape back out of the VBScript at the point where you want the comment to be and insert standard HTML comments, like so...
<%
Dim myVar
Do
SomeStuff args
Until fedUp
%>
<!-- <== Start here
BlockCommentedOut myVar
myVar = 123
--> <== End here
<%
'In line comments.
For i = 0 To 150
DoStuff myVar
Next
%>
回答10:
I'm using a similar solution to @Vasily Hall answer
I'm using Sublime so I need to visualise the comment to my IDE too
<% if 1 = 2 then 'comment %>
<!--div>
...
multicomment goes here
...
</div -->
<% end if 'end comment %>