Many ASP beginners may lose their way in double quotes, single quotes and & signs. The most important thing is that you do not understand the meaning of the three types of symbols, and of course you cannot master their usage well. The following is my opinion on three types of symbols. If the technology is not good, there will inevitably be negligence. I would like to ask everyone to give me more opinions.
1, double quotes ""
The double quotes in ASP can be any characters, strings, and HTML code.
for example
<%response.write ("cnbruce here")%><hr> <%response.write ("<b>cnbruce here</b>")%> |
The page effects produced are: default text and bold text "cnbruce here"
Let’s think about it again. What should I do if I want to add a color effect to the output page text?
1. The general text color is written like this: <font color="#0000ff">cnbruce</font>
2. The method of writing response.write is as follows: response.write("Input the displayed content")
3. If you want to put the above hyperlink code into the response.write, have you found that the double quotes in the write method and the double quotes in the color form a nesting effect?
Response.write("<font color="#0000ff">cnbruce</font>") will inevitably form
4. The debugging results are not optimistic, because the front quotation marks of color match the front quotation marks of write, and the content is <font color=; Similarly, the back quotation marks of color match the back quotation marks of write, and the content is: >cnbruce</font>. The end result is: #0000ff in the middle is lonely.
5, so for the correct result, you can use #0000ff as a string and put it in double quotes, and then the connection between the string and the previous string <font color= and the last string>cnbruce</font> will use the & number
The final result is as follows:
<% response.write("<font color=" & "#0000ff" & ">cnbruce</font>") %> |
2, single quote ''
Just like learning Chinese classes, quotation marks that continue to be placed in double quotes can be used in single quotes.
Then #0000ff in the above statement response.write("<font color="#0000ff">cnbruce</font>") can change its double quotes into single quotes:
response.write("<font color='#0000ff'>cnbruce</font>"), this execution is also correct.
3. Connect characters & symbols
The main function of the & number in ASP is to connect, including: string-string, string-variable, variable-variable and other mixed connections.
For example, the following example:
<% mycolor="#0000ff" response.write ("<font color=' "&mycolor&" '>" & "cnbruce" & "</font>") %> |
One thing that needs to be noted is that the single quotes of color are used in double quotes~! You may be confused, just watch it slowly.
1. Now I have defined a variable mycolor myself. According to the principle, there is no need to add double quotes to the variable in response.write, because adding double quotes means it is a string, not a variable.