.


:




:

































 

 

 

 


Document Object Model (DOM)




HTML- , ( , ) HTML. HTML HEAD BODY, , , .

, :

HTML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www. w3.org/TR/xhtml11/DTD/xhtml11.dtd">
HTML- <html>
HTML <!-- this is comment -->
HTML () <p> </p>
HTML bgcolor=red
, HTML Content of paragraph

HTML- id, getElementById document. BODY:

<p id="myP">Hello, World!</p>

<script type="text/javascript">

alert(document.getElementById("myP").innerHTML);

// Hello World!

var str = "";

str += document.getElementById("myP").nodeName + '\n';

str += document.getElementById("myP").nodeValue + '\n';

str += document.getElementById("myP").nodeType + '\n';

alert(str);

// P null 1

</script>

nodeValue, null, <p> , Hello, World!. , :

document.getElementById("myP").childNodes[0].nodeValue;

DOM :

nodeName ;

nodeValue ;

nodeType , ;

parentNode , ;

childNodes ;

firstChild ;

lastChild ;

previousSibling , ;

nextSibling , ;

attributes ;

ownerDocument document, .

DOM, :

<!-- # 8: DOM-->

<table>

<tr id="firstRow">

<td id="firstCell"></td>

<td id="currentNode" width="10">

<span id="spanNode">

text</span>

<p id="pNode">text</p>

</td>

<td id="lastCell"></td>

</tr>

</table>

<script type="text/javascript">

alert(document.getElementById("currentNode").parentNode.id);

// firstRow

alert(document.getElementById("currentNode").childNodes[0].id);

// spanNode

alert(document.getElementById("currentNode").firstChild.id);

// spanNode

alert(document.getElementById("currentNode").lastChild.id);

// pNode

alert(document.getElementById("currentNode").previousSibling.id);

// firstCell

alert(document.getElementById("currentNode").nextSibling.id);

// lastCell

alert(document.getElementById("currentNode")

.attributes["width"].value);

// 10

alert(document.getElementById("currentNode")

.ownerDocument.nodeName);

// #document

</script>

getElementById(), , . getElementsByName() name, getElementsByTagName() () . document.

DOM , :

createAttribute(name) , ;

createComment(string) HTML-
<!--string -->, ;

createDocumentFragment() ;

createElement(tagName) () ,
;

createTextNode(string) , .

document.





:


: 2016-04-03; !; : 362 |


:

:

.
==> ...

1251 - | 1211 -


© 2015-2024 lektsii.org - -

: 0.013 .