<!
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
>
<
html
>
<
head
>
<
title
>
Dom Example
</
title
>
<
meta
name
="GENERATOR"
content
="Microsoft Visual Studio .NET 7.1"
>
<
meta
name
=ProgId
content
=VisualStudio.HTML
>
<
meta
name
=Originator
content
="Microsoft Visual Studio .NET 7.1"
>
<
script
language
=javascript
>
function
html() {
var
oHtml
=
document.documentElement; alert(oHtml.innerText
+
"
"
+
oHtml.childNodes.length); alert(oHtml.innerHTML); }
function
fist() {
var
oHtml
=
document.documentElement;
var
oHead
=
oHtml.firstChild; alert(
"
innerText:
"
+
oHead.innerText); alert(
"
innerHTML:
"
+
oHead.innerHTML); }
function
lastNode() {
var
oHtml
=
document.documentElement;
var
oBody
=
oHtml.lastChild; alert(
"
innerText:
"
+
oBody.innerText); alert(
"
innerHTML:
"
+
oBody.innerHTML); }
function
html2() {
var
oHtml
=
document.documentElement; alert(oHtml.outerText
+
"
"
+
oHtml.childNodes.length); alert(oHtml.outerHTML); }
function
fist2() {
var
oHtml
=
document.documentElement;
var
oHead
=
oHtml.firstChild; alert(
"
outerText:
"
+
oHead.outerText); alert(
"
outerHTML:
"
+
oHead.outerHTML); }
function
lastNode2() {
var
oHtml
=
document.documentElement;
var
oBody
=
oHtml.lastChild; alert(
"
outerrText:
"
+
oBody.outerText); alert(
"
outerHTML:
"
+
oBody.outerHTML); }
</
script
>
</
head
>
<
body
>
<
p
id
=1
>
hello world!
</
p
>
<
p
>
Isn't this exciting?
</
p
>
<
p
>
You'are learning to user the dom
</
p
>
<
a
>
innerText & innerHtml:
</
a
><
br
>
<
input
type
=button
name
=bt1
value
=fistNode
onclick
="html()"
/>
<
input
type
=button
name
=bt2
value
=fistNode
onclick
="fist()"
/>
<
input
type
=button
name
=bt3
value
=lastNode
onclick
="lastNode()"
/>
<
br
>
<
a
>
outerText & outerHtml:
</
a
><
br
>
<
input
type
=button
name
=bt4
value
=fistNode
onclick
="html2()"
/>
<
input
type
=button
name
=bt5
value
=fistNode
onclick
="fist2()"
/>
<
input
type
=button
name
=bt6
value
=lastNode
onclick
="lastNode2()"
/>
<
br
>
</
body
>
</
html
>
转载请注明原文地址: https://ibbs.8miu.com/read-32218.html