w3pop.com :: ÍøÂçѧԺ :: HTML DOM :: DOM ½éÉÜ
The HTML Document Object Model (HTML DOM) defines a standard way for accessing and manipulating HTML documents.
HTMLÎĵµ¶ÔÏóÄ£ÐÍ(HTML DOM)¶¨ÒåÁËÒ»ÖÖ·ÃÎʲ¢²Ù×÷HTMLÎĵµµÄ±ê×¼·½·¨
Before you continue you should have a basic understanding of the following:
ÔÚÄã¼ÌÐøÇ°ÄãÓ¦¸ÃÓÐÏÂÃæÏà¹Ø·½ÃæµÄ»ù´¡ÖªÊ¶£º
If you want to study these subjects first, find the tutorials on our Home page.
Èç¹ûÄãÏëÏÈѧϰÕâЩ֪ʶµÄ»°£¬ÔÚÎÒÃǵÄÊ×ҳѰÕҽ̳Ì
"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£©
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½¨Á¢ÐµÄÔªËØ¡£ÔªËصÄÎÄ×ÖºÍËüÃǵÄÊôÐÔ±»Ê¶±ðΪµã¡£
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
This coding example shows how the background color of an HTML document can be changed to yellow when a user clicks on it:
Àý×ÓÖеĴúÂëչʾÁËÔõÑùÈñ³¾°ÑÕÉ«ÒòÓû§µÄµã»÷¶ø±äΪ»ÆÉ«£º
<html> |
Try it yourself×Ô¼º³¢ÊÔÏÂ
The example above is explained in details in the next chapter of this tutorial.
ÉÏÃæµÄÀý×ÓÎÒÃÇ»áÔÚÏÂһƪÕÂÀïÏêϸ½âÊÍ