[¶ÁÊé±Ê¼Ç][JavaScriptȨÍþÖ¸ÄÏ(µÚËÄ°æ)][DOM]
1.HTMLÎĵµÊ÷Ðαíʾ
2.Node[] Node.childNodes
//·µ»ØNode¶ÔÏóµÄËùÓÐ×Ö½Úµã
3.Node.firstChild / lastChild /nextSibling(ÏÂÒ»¸öÐֵܽڵã) / previousSibling (ÉÏÒ»¸öÐֵܽڵã) / parentNode
ÊôÐÔ
4.Node.appendChild() / removeChild() / replaceChild(oNewNode
,oOldNode
) / insertBefor(oNewNode,oChildNode
)
5.
³£ÓýڵãÀàÐÍ£º
6.ÉèÖÃÊôÐԵķ½·¨£º
string ELEMENT.getAttribute(sAttribute)
ELEMENT.setAttribute(sAttributeName,sAttributeValue)
ELEMENT.removeAttribute(sAttributeName)
7.ºËÐÄDOM API
8.//±éÀúÎĵµ½Úµã,¼Ç¼½ÚµãÊý
function countTags(node){
var numtags=0;
if(node.nodeType==1)
numtags++;
var children=node.childNodes;
for(var i=0;i<children.length;i++){
numtags+=countTags(children[i]);
}
return numtags;
}
9.ËÑË÷ÎĵµÖÐÌض¨ÔªËØ
collObjects
= object
.getElementsByTagName(
sTagName
)
oElement
= document
.getElementById(
sIDValue
)
10.´´½¨Îı¾ÔªËØ oTextNode
= document
.createTextNode(
[
sText
]
)
11.¸Ä±äÎı¾ÔªËصķ½·¨ÓÐ
TextNode.appendData(string data)
deleteData(nOffect,nCount) /*°ü»»nOffset*/
replaceData(nOffset,nCount,sString) /*nOffest¿ªÊ¼Î»ÖÃ,°üº¬nOffset;nCountÓ°ÏìÊý;sStringÌæ»»Îı¾*/
Ïà¹ØÎĵµ£º
±¾ÎÄת×Ô£ºhttp://www.felixwoo.com/archives/247
×î½üÔÚÍøÉϲéÔÄÁ˲»ÉÙJavascript±Õ°ü(closure)Ïà¹ØµÄ×ÊÁÏ£¬Ð´µÄ´ó¶àÊǷdz£µÄѧÊõºÍרҵ¡£¶ÔÓÚ³õѧÕßÀ´Ëµ±ð˵Àí½â±Õ°üÁË£¬¾ÍÁ¬ÎÄ×ÖÐðÊö¶¼ºÜÄÑ¿´¶®¡£×«Ð´´ËÎĵÄÄ¿µÄ¾ÍÊÇÓÃ×îͨË×µÄÎÄ×Ö½Ò¿ªJavascript±Õ°üµÄÕæʵÃæÄ¿¡£
Ò»¡¢Ê²Ã´ÊDZհü£¿
“¹Ù·½”µÄ½âÊÍÊÇ£º±Õ°üÊ ......
CDATA ÄÚ²¿µÄËùÓж«Î÷¶¼»á±»½âÎöÆ÷ºöÂÔ¡£
¼ÙÈçÎı¾Öаüº¬ÁË´óÁ¿µÄ "<" ºÍ "&" ×Ö·û - ¾ÍÏñ±à³Ì´úÂëÖо³£³öÏÖµÄÇé¿öÒ»Ñù - ÄÇôÕâ¸ö XML ÔªËؾͿÉÒÔ±»¶¨ÒåΪһ¸ö CDATA ²¿·Ö¡£
CDATA Çø¶Î¿ªÊ¼ÓÚ "<![CDATA["£¬½áÊøÓÚ "]]>"£º
<script type="text/javascript">
<![CDATA[
function compare(a,b ......
//¸÷Öֳߴç
s += "\r\nÍøÒ³¿É¼ûÇøÓò¿í£º"+ document.body.clientWidth;
s += "\r\nÍøÒ³¿É¼ûÇøÓò¸ß£º"+ document.body.clientHeight;
s += "\r\nÍøÒ³¿É¼ûÇøÓò¸ß£º"+ document.body.offs ......
Ò»¡¢DOM»ù´¡
1.½Úµã(node)²ã´Î
Document££×²ãµÄ½Úµã£¬ËùÓеÄÆäËû½Úµã¶¼ÊǸ½ÊôÓÚËüµÄ¡£
DocumentType££DTDÒýÓã¨Ê¹ÓÃ<!DOCTYPE>Óï·¨£©µÄ¶ÔÏó±íÏÖÐÎʽ£¬Ëü²»ÄÜ°üº¬×ӽڵ㡣
DocumentFragment££¿ÉÒÔÏñDocumentÒ»ÑùÀ´±£´æÆäËû½Úµã¡£
Element££±íʾÆðʼ±êÇ©ºÍ½áÊø±êÇ©Ö®¼äµÄÄÚÈÝ£¬ÀýÈç<tag></tab ......
²Î¿¼×ÊÁÏ:¡¶javascriptȨÍþÖ¸ÄϵÚÎå°æ¡·
===============±äÁ¿==============
1¡¢javaScriptÊÇÒ»ÖÖÈõÀàÐ͵ÄÓïÑÔ£¬ÓÃvarÓï¾ä¼´¿ÉÉùÃ÷Ò»¸ö±äÁ¿¡£
2¡¢Èç¹û²»ÓÃvarÓï¾äÉùÃ÷¶øÖ±½Ó¸øÒ»¸ö±äÁ¿¸³Öµ£¬ÄÇÕâ¸ö±äÁ¿½«±»ÒþʽÉùÃ÷Ϊȫ¾Ö±äÁ¿¡£
3¡¢Èç¹ûº¯ÊýÄÚ²¿ÓÃvarÓï¾äÉùÃ÷ÁËÒ»¸öÓëijȫ¾Ö±äÁ¿Í¬ÃûµÄ±äÁ¿£¬ÔòÔÚº¯ÊýÖÐÈ«¾Ö±äÁ¿±»ÆÁ±ÎÁË ......