<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script>
document.write("<h1 stylle='coloe:red'>HELLO</h1!><br>");
console.log("HELLO \n Javascrit")
var a = 10;
document.write("a1=" + a + " ,a1-type =" + typeof (a) + "<br>");
var a = "TEST";
document.write("a2=" + a + " ,a2-type =" + typeof (a) + "<br>");
var n = null;
document.write("n=" + n + " ,n-type =" + typeof (n) + "<br>");
var u;
document.write("u=" + u + " ,u-type =" + typeof (u) + "<br>");
</script>
</head>
<body>
<!--preformat pre ,裡面的字寫甚麼樣子就顯是甚麼樣子-->
222 2222<br><!--列印出來不會有空格,而且需用br換行-->
222    2222<!--這樣才會有空格-->
<pre>
222 2222<!--列印出來有會有空格且自己換行,但字體變小-->
222 222
</pre>
</body>
</html>
所以可以如下配合writeln使用pre,就不用每行用br換行了:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script>
document.write("<h1 stylle='coloe:red'>HELLO</h1!><br>");
console.log("HELLO \n Javascrit")
document.write("<pre>")
var a = 10;
document.writeln("a1=" + a + " ,a1-type =" + typeof (a) );
var a = "TEST";
document.writeln("a2=" + a + " ,a2-type =" + typeof (a));
var n = null;
document.writeln("n=" + n + " ,n-type =" + typeof (n));
var u;
document.writeln("u=" + u + " ,u-type =" + typeof (u));
document.write("</pre>")
</script>
</head>
<body>
</body>
</html>
也可以這樣寫,用 with (document)把下面包起來就不用一個個打document了
var a = 10;
with (document) {
write("<pre>");
writeln("a=" + a + " typeof(a)=" + typeof (a));
var a = "EEIT86";
writeln("a=" + a + " typeof(a)=" + typeof (a));
var n = null;
writeln("n=" + n + " typeof(n)=" + typeof (n));
var u;
writeln("u=" + u + " typeof(u)=" + typeof (u));
write("</pre>");
}
留言列表