jsÖеĽڵãÊÇʲôÒâ˼
½ÚµãÊÇ javascript ÖÐÌåÏÖ dom Ê÷ÔªËصŤ¾ß£¬Ìṩ²Ù×÷ html ½á¹¹µÄÒªÁìºÍÊôÐÔ¡£½ÚµãÀàÐÍ°üÀ¨ÔªËؽڵ㣨Èç £©¡¢Îı¾½Úµã¡¢×¢ÊͽڵãºÍÎĵµ½Úµã¡£½ÚµãÓµÓÐÊôÐÔ£¨Èç nodename¡¢nodetype¡¢nodevalue£©ºÍÒªÁ죨Èç appendchild()¡¢removechild¡¢clonenode()£©£¬ÓÃÓÚʹÓà dom Ê÷¡£
JS ÖеĽڵã
ʲôÊǽڵ㣿
ÔÚ JavaScript ÖУ¬½ÚµãÊÇÒ»¸öÌåÏÖ DOM Ê÷ÖÐÔªËØµÄ JavaScript ¹¤¾ß¡£ËüÌṩÁËһϵÁÐÒªÁìºÍÊôÐÔ£¬Ê¹¿ª·¢Ö°Ô±Äܹ»Ê¹ÓúÍÐÞ¸ÄÒ³ÃæÉ쵀 HTML ½á¹¹¡£
½ÚµãÀàÐÍ
½ÚµãÓвî±ðµÄÀàÐÍ£¬Ã¿ÖÖÀàÐÍ´ú±í DOM Ê÷ÖÐÔªËصÄÌض¨ÀàÐÍ£º
ÔªËؽڵ㣺ÌåÏÖ HTML ÔªËØ£¬Èç »ò
¡£
Îı¾½Úµã£ºÌåÏÖÔªËØÖ®¼äµÄÎı¾ÄÚÈÝ¡£
×¢Êͽڵ㣺ÌåÏÖ HTML ×¢ÊÍ¡£
Îĵµ½Úµã£ºÌåÏÖÕû¸öÎĵµ¡£
½ÚµãÊôÐÔ
½ÚµãÓµÓÐÐí¶àÊôÐÔ£¬ÓÃÓÚ»ñÈ¡»òÉèÖýڵãµÄÐÅÏ¢£¬°üÀ¨£º
nodeName£º½ÚµãµÄÃû³Æ£¬ÀýÈç “DIV” »ò “#text”¡£
nodeType£º½ÚµãµÄÀàÐÍ£¬Èç 1£¨ÔªËؽڵ㣩¡¢3£¨Îı¾½Úµã£©»ò 8£¨×¢Êͽڵ㣩¡£
nodeValue£º¹ØÓÚÎı¾½Úµã£¬Ëü°üÀ¨Îı¾ÄÚÈÝ£»¹ØÓÚÔªËؽڵ㣬Ëüͨ³£Îª null¡£
childNodes£ºÒ»¸ö°üÀ¨½ÚµãËùÓÐ×Ó½ÚµãµÄÜöÝÍ¡£
parentNode£º¸¸½Úµã¡£
½ÚµãÒªÁì
½Úµã»¹¾ßÓÐÐí¶àÒªÁ죬ÓÃÓÚʹÓà DOM Ê÷£¬°üÀ¨£º
appendChild()£º½«×Ó½Úµã×·¼Óµ½½ÚµãµÄĩβ¡£
insertBefore()£º½«×Ó½Úµã²åÈëµ½ÏÖÓÐ×Ó½Úµã֮ǰ¡£
removeChild()£ºÒƳý×ӽڵ㡣
replaceChild()£ºÓÃÁíÒ»¸ö½ÚµãÌæ»»×ӽڵ㡣
cloneNode()£º½¨Éè½ÚµãµÄ¿Ë¡¡£
hasChildNodes()£º¼ì²é½ÚµãÊÇ·ñ¾ßÓÐÈκÎ×ӽڵ㡣