Halaman

Selasa, 13 Juli 2010

JavaScript "document.write"

One of the most basic JavaScript commands is document.write.
This simply prints the specified text to the page. To print text
literally, enter the text in single quote marks inside parentheses like
so:


	document.write('Hello World!');

The code above will cause the phrase "Hello World!" to appear on the
page.


You can also use document.write to print
variables. Enter the variable name without quotes, like so:


	var mytext = "Hello again";<br />	document.write(mytext);<br />

Note that if quote marks are placed around the variable name, the
variable name itself will be printed (instead of the variable value).
You can also combine variable values and text strings by using the +
sign:


	var colour1 = "purple";<br />	var colour2 = "pink";<br />	document.write('<p>colour1: ' + colour1 + '<br>colour2: ' + colour2 + '</p>');<br />

Notice the way the variable names are used literally as well as for
passing the values. This will print the following:



colour1: purple
colour2: pink



Remember, text inside quotes will be printed literally, text with no
quotes is assumed to be a variable.

colour1: purple
colour2: pink

Tidak ada komentar: