1.document Properties
- Cookie-User Cookie
- Title-the text defined in the title tag of the current page
- URL--The URL of the current page
Document represents the contents of an HTML document, so it can be used to represent elements that are loaded in the document, all accessed through a collection.
- Anchors-a collection of all anchors (a name= "Aname") in the document
- Applets--a collection of content represented by all applet tags in the document
- Embeds--a collection of content represented by all embed tags in a document
- Forms-a collection of the content represented by all form labels in a document
- Images--a collection of content represented by all the image tags in the document
- Links--A collection of content represented by all a (link) tags in a document
2.document function
- JavaScript Write () function
- JavaScript Writeln () function
- JavaScript Document.open () function
- JavaScript Document.close () function
A. document.write-writing a string in a document
Write function Syntax
document
.
write
(
str
)
;
Write function Arguments
B.document.writeln--Writes a string in the document and adds a newline character to the end of the string
C.document.open--Open a document already loaded
Example
var
win
=
window
.
open
(
"
about:blank
"
,
"
dreamdu
"
)
;
win
.
document
.
open
(
)
;
win
.
document
.
write
(
"
welcome to dreamdu!
"
)
;
win
.
document
.
close
(
)
;
Start by creating a new blank document, opening open, writing the content, and closing the document close when finished.
document.open function Syntax
window
.
document
.
open
(
)
;
D.document.close--Used to close the document opened by the Document.open method
document.close
window
.
document
functional
.
language
close
(
)
;
3. Use document to index elements within a page
You can use the collection of elements in a number or name index page, and the properties of each element become the properties of the corresponding object in the collection.
Example
<
form
name
=
"
form1
"
><
a
href
=
"
http://www.dreamdu.com/xhtml/
"
name
=
"
a1
"
>
xhtml
</
a
></
form
>
<
form
name
=
"
form2
"
><
a
href
=
"
http://www.dreamdu.com/css/
"
name
=
"
a2
"
>
css
</
a
></
form
>
<
form
name
=
"
form3
"
><
a
href
=
"
http://www.dreamdu.com/javascript/
"
name
=
"
a3
"
>
javascript
</
a
></
form
>
<
input
type
=
"
button
"
value
=
"
显示第二个表单的名称
"
onclick
=
"
alert(document.forms[1].name)
"
/>
<
input
type
=
"
button
"
value
=
"
显示第二个表单的名称第二种方法
"
onclick
=
"
alert(document.forms[‘form2‘].name)
"
/>
<
input
type
=
"
button
"
value
=
"
显示第三个链接的名称
"
onclick
=
"
alert(document.links[2].name)
"
/>
<
input
type
=
"
button
"
value
=
"
显示第三个链接的名称第二种方法
"
onclick
=
"
alert(document.links[‘a3‘].name)
"
/>
<
input
type
=
"
button
"
value
=
"
显示第三个链接href属性的值
"
onclick
=
"
alert(document.links[2].href)
"
/>
Method that represents the second form: document.forms[1] or document.forms["Form2"]
Method that represents the third link: document.links[2] or document.links["A3"]
A method that represents the third link href attribute: document.links[2].href
JavaScript Document Object