ÍøÂçѧԺ w3popÉçÇø ÍøÂç×ÊÔ´ ITÐÂÎÅ

w3pop.com :: ÍøÂçѧԺ :: HTML DOM :: DOM ½éÉÜ

»áÔ±µÇ½

ÕʺÅ

ÃÜÂë

»Ø´ð

¼ÇסÃÜÂë

Íü¼ÇÃÜÂë? ×¢²á

HTML DOM
DOM TableRow ¶ÔÏ..
DOM Textarea ¶ÔÏ..
DOM Window ¶ÔÏó

DOM ½éÉÜ


×÷Õß:w3pop.com ·­Òë/ÕûÀí:w3pop.com ·¢²¼:2007-04-28 ÐÞ¸Ä:2007-06-17 ä¯ÀÀ:11878 :: ::

The HTML Document Object Model (HTML DOM) defines a standard way for accessing and manipulating HTML documents.
HTMLÎĵµ¶ÔÏóÄ£ÐÍ(HTML DOM)¶¨ÒåÁËÒ»ÖÖ·ÃÎʲ¢²Ù×÷HTMLÎĵµµÄ±ê×¼·½·¨


What You Should Already Know
ÄãÓ¦¸ÃÒѾ­ÖªµÀÄÄЩ

Before you continue you should have a basic understanding of the following:
ÔÚÄã¼ÌÐøÇ°ÄãÓ¦¸ÃÓÐÏÂÃæÏà¹Ø·½ÃæµÄ»ù´¡ÖªÊ¶£º

  • HTML / XHTML
  • JavaScript

If you want to study these subjects first, find the tutorials on our Home page.
Èç¹ûÄãÏëÏÈѧϰÕâЩ֪ʶµÄ»°£¬ÔÚÎÒÃǵÄÊ×ҳѰÕҽ̳Ì


What is the DOM?
ʲôÊÇDOM£¿

"The W3C Document Object Model (DOM) is a platform and language neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document."
“W3CÎĵµ¶ÔÏóÄ£ÐÍ£¨DOM£©ÊÇÒ»¸öÄܹ»ÈóÌÐòºÍ½Å±¾¶¯Ì¬·ÃÎʺ͸üÐÂÎĵµÄÚÈÝ¡¢½á¹¹ºÍÑùʽµÄÓïÑÔÆ½Ì¨”

The W3C DOM provides a standard set of objects for representing HTML and XML documents, and a standard interface for accessing and manipulating them.
W3C DOMÌṩÁ˱ê×¼µÄHTMLºÍXML¶ÔÏ󼯣¬²¢ÓÐÒ»¸ö±ê×¼µÄ½Ó¿ÚÀ´·ÃÎʲ¢²Ù×÷ËûÃÇ

The DOM is separated into different parts (Core, XML, and HTML) and different levels (DOM Level 1/2/3):
DOM±»·ÖΪ²»Í¬µÄ²¿·Ö£¨ºËÐÄ£¬XMLºÍHTML£©ºÍ²»Í¬µÄ°æ±¾£¨DOM 1/2/3£©

  • Core DOM - defines a standard set of objects for any structured document
    ¶¨ÒåÁËÈÎÒâ½á¹¹ÎĵµµÄ±ê×¼¶ÔÏ󼯺Ï
  • XML DOM - defines a standard set of objects for XML documents
    ¶¨ÒåÁËÕë¶ÔXMLÎĵµµÄ±ê×¼¶ÔÏ󼯺Ï
  • HTML DOM - defines a standard set of objects for HTML documents
    ¶¨ÒåÁËÕë¶ÔHTMLÎĵµµÄ±ê×¼¶ÔÏ󼯺Ï

What is the HTML DOM?
ʲôÊÇHTML DOM£¿

  • The HTML DOM is the Document Object Model for HTML
    HTML DOMÊÇÕë¶ÔHTMLµÄÎĵµ¶ÔÏóÄ£ÐÍ
  • The HTML DOM is platform and language independent
    HTML DOMÊǶÀÁ¢µÄÓïÑÔºÍÆ½Ì¨
  • The HTML DOM defines a standard set of objects for HTML, and a standard way to access and manipulate HTML documents
    ¶¨ÒåÁËÕë¶ÔHTMLµÄ±ê×¼¶ÔÏ󼯺ÏÒÔ¼°·ÃÎʺͲÙ×÷HTMLÎĵµµÄ·½·¨
  • The HTML DOM is a W3C standard
    HTML DOMÊÇÒ»¸öW3CµÄ±ê×¼

The HTML DOM views HTML documents as a tree structure of elements embedded within other elements. All elements, their containing text and their attributes, can be accessed through the DOM tree. Their contents can be modified or deleted, and new elements can be created by the DOM. The elements, their text, and their attributes are all known as nodes.
HTML DOM½«HTMLÎĵµÊÓΪǶÌׯäËûÔªËØµÄÊ÷ÐÍ½á¹¹ÔªËØ¡£ËùÓеÄÔªËØ£¬ËüÃǰüº¬µÄÎÄ×ÖÒÔ¼°ËûÃǵÄÊ÷ÐͶ¼¿ÉÒÔ±»DOMÊ÷Ëù·ÃÎʵ½¡£ËüÃǵÄÄÚÈÝ¿ÉÒÔÐ޸ĺÍɾ³ý£¬²¢ÇÒ¿ÉÒÔͨ¹ýDOM½¨Á¢ÐµÄÔªËØ¡£ÔªËصÄÎÄ×ÖºÍËüÃǵÄÊôÐÔ±»Ê¶±ðΪµã¡£


We Will Use JavaScript
ÎÒÃǽ«Ê¹ÓÃJS

The HTML DOM is platform and language independent. It can be used by any programming language like Java, JavaScript, and VBScript.
HTML DOMÊǶÀÁ¢µÄÓïÑÔÆ½Ì¨£¬Ëü¿ÉÒÔ±»ÈκεijÌÐòÓïÑÔËùʹÓÃJAVA,JS,VBS£©

In this tutorial we will use JavaScript.
ÔÚÕâ¸ö½Ì³ÌÀïÎÒÃÇʹÓõÄÊÇJS


An HTML DOM Example
Ò»¸öHTML DOMµÄÀý×Ó

This coding example shows how the background color of an HTML document can be changed to yellow when a user clicks on it:
Àý×ÓÖеĴúÂëչʾÁËÔõÑùÈñ³¾°ÑÕÉ«ÒòÓû§µÄµã»÷¶ø±äΪ»ÆÉ«£º

<html>

<head>
<script type="text/javascript">
function ChangeColor()
{
document.body.bgColor="yellow"
}
</script>

</head>

<body onclick="ChangeColor()">
Click on this document!
</body>

</html>

Try it yourself×Ô¼º³¢ÊÔÏÂ

The example above is explained in details in the next chapter of this tutorial.
ÉÏÃæµÄÀý×ÓÎÒÃÇ»áÔÚÏÂһƪÕÂÀïÏêϸ½âÊÍ

ÆÀÂÛ (2) 1 All