📄 js_special_characters.asp@output=print
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JavaScript Special Characters</title>
<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="Keywords" content="xml,tutorial,html,dhtml,css,xsl,xhtml,javascript,asp,ado,vbscript,dom,sql,colors,soap,php,authoring,programming,training,learning,beginner's guide,primer,lessons,school,howto,reference,examples,samples,source code,tags,demos,tips,links,FAQ,tag list,forms,frames,color table,w3c,cascading style sheets,active server pages,dynamic html,internet,database,development,Web building,Webmaster,html guide" />
<meta name="Description" content="Free HTML XHTML CSS JavaScript DHTML XML DOM XSL XSLT RSS AJAX ASP ADO PHP SQL tutorials, references, examples for web building." />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "../../https@ssl./default.htm" : "../../www./default.htm");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-3855518-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>
</head>
<body>
<p>From <b>http://www.w3schools.com</b> (Copyright Refsnes Data)</p>
<h1>JavaScript Special Characters</h1>
<a href="js_onerror.asp"><img alt="previous" border="0" src="../images/btn_previous.gif" width="100" height="20" /></a>
<a href="js_guidelines.asp"><img alt="next" border="0" src="../images/btn_next.gif" width="100" height="20" /></a>
<hr />
<p class="intro">In JavaScript you can add special characters to a text string
by using the
backslash sign.</p>
<hr />
<h2>Insert Special Characters</h2>
<p>The backslash (\) is used to insert apostrophes, new lines, quotes, and other
special characters into a text string.</p>
<p>Look at the following JavaScript code:</p>
<table class="ex" cellspacing="0" border="1" width="100%" id="table1"><tr><td>
<pre>var txt="We are the so-called "Vikings" from the north.";
document.write(txt);</pre>
</td></tr></table>
<p>In JavaScript, a string is started and stopped with either single
or double quotes. This means that the string above will be chopped to: We are the so-called</p>
<p>To solve this problem, you must place
a backslash (\) before each double quote in "Viking". This turns each
double quote into a string literal:</p>
<table class="ex" cellspacing="0" border="1" width="100%" id="table3"><tr><td>
<pre>var txt="We are the so-called \"Vikings\" from the north.";
document.write(txt);</pre>
</td></tr></table>
<p>JavaScript will now output the proper text string: We are the so-called "Vikings" from the north.</p>
<p>Here is another example:</p>
<table class="ex" cellspacing="0" border="1" width="100%" id="table4"><tr><td>
<pre>document.write ("You \& I are singing!"); </pre>
</td></tr></table>
<p>The example above will produce the following output:</p>
<table class="ex" cellspacing="0" border="1" width="100%" id="table5"><tr><td>
<pre>You & I are singing!</pre>
</td></tr></table>
<p>The table below lists other special characters that can be added to a text
string with the backslash sign:</p>
<table class="ex" cellspacing="0" border="1" width="100%" id="table3"><tr>
<th align="left">
Code</th><th align="left">
Outputs</th></tr><tr><td>
\'</td><td>
single quote</td></tr><tr><td>
\"</td><td>
double quote</td></tr><tr><td>
\&</td><td>
ampersand</td></tr><tr><td>
\\</td><td>
backslash</td></tr><tr><td>
\n</td><td>
new line</td></tr><tr><td>
\r</td><td>
carriage return</td></tr><tr><td>
\t</td><td>
tab</td></tr><tr><td>
\b</td><td>
backspace</td></tr><tr><td>
\f</td><td>
form feed</td></tr></table>
<br />
<hr />
<a href="js_onerror.asp"><img alt="previous" border="0" src="../images/btn_previous.gif" width="100" height="20" /></a>
<a href="js_guidelines.asp"><img alt="next" border="0" src="../images/btn_next.gif" width="100" height="20" /></a>
<p>From <b>http://www.w3schools.com</b> (Copyright Refsnes Data)</p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -