What's the difference between "<%" and "<%=" in embedded VBScript?
I am working on a code base which as VBScript code embedded in HTML. I've noticed the following two different tags around said lines of code
<%= MyFunc(val1) %>
and
&开发者_Python百科lt;% MyFunc(val1) %>
What is the difference in using the "=" character at the beginning of these sections?
<%
evaluates an expression in server code but doesn't emit output.
<%=
also evaluates the expression but wraps the result in Response.Write, so it produces output.
When you see:
<%= MyFunc() %>
it really means:
<%
Response.Write( MyFunc() )
%>
Its short hand for writting output to the response.
<%
MyFunc()
%>
The above will just run the code but won't write it to the response unless it has some Response.Write
's inside the Function/Sub itself.
精彩评论