📄 js_howto.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 How To</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 How To ...</h1>
<a href="js_intro.asp"><img border="0" alt="previous" src="../images/btn_previous.gif" width="100" height="20" /></a>
<a href="js_whereto.asp"><img border="0" alt="next" src="../images/btn_next.gif" width="100" height="20" /></a>
<hr />
<p class="intro">The HTML <script> tag is used to insert a JavaScript into an HTML
page.</p>
<hr />
<h2>Examples</h2>
<p><a target="_blank" href="tryit.asp@filename=tryjs_text">Write text with
Javascript</a><br />
The example demonstrates how to use JavaSript to write text on a web page.</p>
<p><a target="_blank" href="tryit.asp@filename=tryjs_formattext">Write HTML with
Javascript</a><br />
The example demonstrates how to use JavaScript to write HTML tags on a web page.</p>
<hr />
<h2>How to Put a JavaScript Into an HTML Page</h2>
<table width="100%" border="1" class="ex" cellspacing="0">
<tr><td>
<pre><html>
<body>
<span class="insert"><script type="text/javascript">
document.write("Hello World!");
</script>
</span></body>
</html></pre>
</td></tr>
</table>
<p>The code above will produce this output on an HTML page:</p>
<table width="100%" border="1" class="ex" cellspacing="0"><tr><td>
Hello World!
</td></tr></table>
<h3>Example Explained</h3>
<p>To insert a JavaScript into an HTML page, we use the <script> tag.
Inside the <script> tag we
use the "type="
attribute to define the scripting language.</p>
<p>So, the <script type="text/javascript"> and </script> tells where the
JavaScript starts and ends:</p>
<table width="100%" border="1" class="ex" cellspacing="0"><tr><td>
<pre><html>
<body>
<span class="insert"><script type="text/javascript">
...
</script>
</span></body>
</html></pre>
</td></tr></table>
<p>The word <b>document.write</b> is a standard JavaScript command for writing output to a page.</p>
<p>By entering the document.write command between the <script>
and </script> tags, the browser will recognize it as a JavaScript command and
execute the code line. In this case the browser will write Hello World! to the page:</p>
<table width="100%" border="1" class="ex" cellspacing="0" id="table1"><tr><td>
<pre><html>
<body>
<span class="insert"><script type="text/javascript">
document.write("Hello World!");
</script>
</span></body>
</html></pre>
</td></tr></table>
<p><a target="_blank" href="tryit.asp@filename=tryjs_text">Try it yourself.</a></p>
<p><b>Note:</b> If we had not entered the <script> tag, the browser would have
treated the document.write("Hello World!") command as pure text, and just write the entire line on the page.</p>
<p><a target="_blank" href="tryit.asp@filename=tryjs_textx">Try it yourself.</a></p>
<hr />
<h2>HTML Comments to Handle Simple Browsers</h2>
<p>Browsers that do not support JavaScript will display JavaScript as page
content. </p>
<p>To prevent them from doing this, and as a part of the JavaScript standard,
the HTML comment tag can be used to "hide" the JavaScript. Just add an HTML
comment tag <!-- before the first JavaScript statement, and a --> (end of
comment) after the last JavaScript statement.</p>
<table width="100%" border="1" class="ex" cellspacing="0" id="table2"><tr><td>
<pre><html>
<body><span class="insert">
<script type="text/javascript">
<!--
document.write("Hello World!");
//-->
</script>
</span></body>
</html></pre>
</td></tr></table>
<p>The two forward slashes at the end of comment line (//) is the JavaScript comment symbol.
This prevents JavaScript from executing the --> tag.</p>
<hr />
<a href="js_intro.asp"><img border="0" alt="previous" src="../images/btn_previous.gif" width="100" height="20" /></a>
<a href="js_whereto.asp"><img border="0" alt="next" 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 + -