ASP JavaScript Tutorial - Lesson 02 Escape Characters

xiaoxiao2021-04-09  480

Escape Characters

NOT OUT OF PLACE:

The instruction of Escape Characters in Lesson 02 seems out of place. But it's not. Escape Characters are an integral part of using JavaScript in ASP. Lesson 02 is exactly the right spot for escape characters. Without escape characters, you will struggle to write effective ASP Scripts in JavaScript. Sorry.

Get Started:

Below Is The ASP Script for Lesson 02.

<% @ Language = "javascript"%>

<%

Response.write (" / r")

Response.write (" /" Hello WORLD / "
/ r")

Response.write (" 'Hello World'
/ r")

Response.write (" / r")

%>

Click Here to Run The Script in a New window.

Remember in Lesson 01 How The entire html output was on one line. The escape character setow us to add carrriage returns.

Below is the html source code as seen on the client side.

"Hello World"

'Hello World'

Escape return:

I'VE Reprinted a Single Line of ASP Script Below. Look at the "/ r" at the end of the line.

Response.write (" /" Hello WORLD / "
/ r")

The "/ r" is a special character representing a carriage return. It's how I got the separate lines of HTML output on ... well ... separate lines. That's vitally important on larger applications and larger pages. I said it before, But I'll Say It Again. Trust Me; You can't Find Bugs if you can' you're putting out to the client.escape quote:

.......................... ..

Response.write ("" Hello World "
")

I Would Get An Error Code, Which is Copied Below.

Microsoft JScript Compiration Error '800A03EE'

EXpected ')'

/ASP/SECTION01/Script02.asp, Line 4

Response.write ("" Hello World "
")

----------------------------- ^

NO Escape:

What if I don't like escape character? Do i Have to use the them?

You can Limp Along without them. Consider the line below.

Response.write (" 'Hello World'
")

/ bbackspace / cdcontrol-d / fform feed / nnew line / rcarriage return / ttab / xnnhexadecimal / 0nnascii escape characters / 'Single Quote / "Double Quote // Backslash

You can interchange Single Quotes with Double Quotes. But It Works. Even with That Said, HTML AESTHETICS Are The Least Important Reason To Use escape character.

The List:

A Far More Important Reason To Utilize Escape Characters Is That Allows US To Output A Whole List of Special Characters.Most Important:

But the most important reason to use Escape Characters (at least for any sophisticated application) is for your database connection. (Database connections get their own lesson later on.) Compare the two Connection Strings below.

Var connection = "provider = microsoft.jet.Oledb.4.0; data source =" server.mappath ("// ToplevelVirtualFolder") "//database/MyDatabase.mdb;"

DIM Connection; connection = "provider = microsoft.jet.Oledb.4.0; data source =" & server.mappath ("/ toplevvirtualfolder" & "/Database/mydatabase.mdb;"

Next Up:

TheRe's Another Little Tool We Absolutely Must Have to Write ASP JavaScript. And That's in Lesson 03.

转载请注明原文地址:https://www.9cbs.com/read-133089.html

New Post(0)