<script type = "Text/javascript" >
Write text using the document.write () output stream
document.write ("hello,world!");
Write HTML using the document.write () output stream
document.write ("
</script>
<body onmousedown = "Show_coords (event)" >
The <p>referrer property returns the URL of the document that is loading this document. </p>
<p> the title of the document is:
The URL of the document:
The referer of the text:
<script type = "Type/javascript" >
Returns the title of the current document
document.write ("Document.title");
Returns the URL of the current text
document.write ("document. URL ");
Returns the referer of the current text
document.write ("Document.referer");
Returns the server domain name of the download current document
document.write ("Document.domain");
Using the getElementById () method
function GetValue () {
var x = document.getElementById ("MyHeader");
alert (x.innerhtml);
}
Using the Getelementbyname () method
function getelements () {
var X = document.getelementbyname ("Myinput");
alert (x.length);
}
Open a new document, enter some content, and then close it.
function Creatnewdoc () {
var newdoc = Document.open ("text.html", "replace");
var txt = "<body>
Newdoc.write ("txt");
Newdoc.close ();
}
Returns the number of sights in a document
document.write ("Document.anchor.length");
Returns the innerHTML of the first second in a document
document.write (document.anchor[0].innerhtml);
Calculate the number of forms in a document
document.write ("document contains" + Document.forms.length + "forms");
accessing items in a collection
document.write ("<p> first form name is" + Document.form[0].name + "</p>");
document.write ("<p>" + document.getElementById ("Form1"). Name + "</p>");
Calculate the number of images in a document
document.write ("The document contains" + Document.img.length + "photos");
Which mouse button is clicked
function Whichbutton (event) {
var btnnum = Event.button;
if (Btnnum = = 2) {
Alert ("You check the right button!");
}else if (Btnnum = = 0) {
Alert ("Check the left button!");
}else if (btnnum = = 1) {
Alert ("You check the middle button!");
}else{
Alert ("You clicked the + + sign key", I am not able to determine its name.) );
}
}
What is the coordinates of the cursor?
function Show_coords (event) {
X1 = Event.clientx;
Y1 = Event.clienty;
Alert ("x coordinate is" + X1, "y coordinates are" +y1);
}
Is the Unicode button pressed?
function WhichButton1 (event) {
alert (Event.keycode);
}
Relative to the screen, what is the cursor coordinates?
function coordinates (event) {
A = Event.screenx;
b = Event.screeny;
Alert ("x=" + A, "y=" + b);
}
Is the SHIFT key pressed?
function Iskeypressed (event) {
if (Shiftkey = = 1) {
Alert ("The Shiftkey was checked!");
}else{
"The SHIFT key is not pressed!"
}
}
</script>
</p>
Is the SHIFT key pressed?
<p> Click a location in the document and the message box will tell you if you pressed the SHIFT key. </p>
Relative to the screen, what is the cursor coordinates?
<p> Click a location in the document and the message box displays the mouse's coordinates for the screen. </p>
What is the coordinates of the cursor?
<p><b> Note:</b> When testing This example, make sure that the frame on the right has the focus. </p>
<p> press a key on the keyboard. The message box prompts for the Unicode of the key. </p>
<p> Click in the document and a message box displays the x and y coordinates of the text. </p>
Which mouse button is clicked
<p> Click the mouse button in the document and a message box will prompt you to click on which mouse key. </p>
Calculate the number of images in a document
<br>
accessing items in a collection
<form id = "Form1" name = "Form1" >your name <input type = "text" size = "></form>"
<form id = "Form2" name = "Form2" >your cars<input type = "text" size = "></form>"
<p> to access the items in the collection, you can either access the project name or use the project number. </p>
Calculate the number of forms in a document
<form name = "Form1" ></form>
<form name = "Form2" ></form>
<form name = "FORM3" ></form>
Returns the number of sights in a document
<a name = "One" > First seedling </a>
<a name = "Two" > Second seedling </a>
<a name = "three" > Third seedling </a>
Open a new document, enter some content, and then close it.
<input type = "button" onclick = "Creatnewdoc ()" "Value =" opens and then writes a new document. ">
Using the Getelementbyname () method
<input type = "text" id = "myinput" size = "><br>"
<input type = "text" id = "myinput" size = "><br>"
<input type = "text" id = "myinput" size = "><br>"
<br>
<input type = "button" onclick = "getelements ()" value = "the element named" Myinput "has several" >
<H1 id = "MyHeader" onclick = "GetValue ()" >headline
<p> Click on the title to display its value. </p>
</body>
<//html>
2015/12/15--document Object