DHTML °³Ã¼µéÀÇ Á÷Á¢ ÈļÕÀÎ ÀÚ½Ä °³Ã¼µéÀÇ Ä÷º¼ÇÀ» ¹ÝȯÇÑ´Ù.
all Ä÷º¼Ç°ú À¯»çÇÏ¸ç °³Ã¼ÀÇ ÀÚ½Ä °³Ã¼µéÀ» ¹ÝȯÇÏ°í children °³Ã¼µéÀº ¿¤·¹¸àÆ®µéÀ» Æ÷ÇÔÇÒ ¼ö ÀÖ´Ù.
°³Ã¼ | script | HTML | ±Ô°Ý | IE |
---|
¼³¸íÀ» À§ÇÑ ¿¹Á¦
ÇÏÀ̶óÀÌÆ® DIV |
javascript¸¦ ÀÌ¿ëÇÑ Ä÷º¼Ç ¿¹Á¦
DIV ¼ÓÀÇ ¹®´Ü °³Ã¼
ÀÚ½Ä ¼ÓÀÇ ÀÚ½Ä SPANindex | ÀÚ½Ä °³Ã¼ | id | ¸ðü °³Ã¼ | °³Ã¼ ³»¿ë |
---|
<SCRIPT> var childrenColl,rowsColl,cellsColl; //ÀÚ½Ä, ÁÙ, Ä °³Ã¼µéÀÇ ¼±¾ð function getCollections(){ childrenColl=parentObj.children; // ¸ðüÀÇ Àڽĵé Ä÷º¼ÇÀ» ¾ò´Â´Ù. getChildren(childrenColl,parentObj); // °³Ã¼ÀÇ Àڽݳü¸¦ ¾ò´Â ±â´ÉÇÔ¼ö¸¦ È£ÃâÇÑ´Ù. childrenColl=childObj.children; getChildren(childrenColl,childObj); } function getChildren(childrenColl,childrenCollection){ for(idx=0;idx< childrenColl.length;idx++){ rowsColl=tableObj.insertRow(); // »õ·Î¿î ÁÙÀ» ¸¸µë. cellsColl=rowsColl.insertCell(); // »õ·Î¿î ÄÀ» ¸¸µë. cellsColl.align='center'; cellsColl.style.color='green'; cellsColl.innerText=idx; // ÀÚ½ÄÀÇ Å±×À̸§ÀÌ µé¾î°¡´Â ÄÀ» ¸¸µç´Ù. cellsColl=rowsColl.insertCell(); cellsColl.align='center'; cellsColl.innerText=childrenCollection.children.item(idx).tagName; // id³ª nameÀÌ µé¾î°¡´Â ÄÀ» ¸¸µç´Ù. cellsColl=rowsColl.insertCell(); cellsColl.align='center'; if(childrenCollection.children.item(idx).name!=null){ cellsColl.innerText=childrenCollection.children.item(idx).name; }else{ cellsColl.innerText=childrenCollection.children.item(idx).id; } cellsColl=rowsColl.insertCell(); // ¸ðü °³Ã¼ÀÇ id°¡ µé¾î°¡´Â ÄÀ» ¸¸µç´Ù. cellsColl.align='center'; cellsColl.innerText=childrenCollection.id; cellsColl=rowsColl.insertCell(); // °³Ã¼ÀÇ ³»¿ëÀÌ µé¾î°¡´Â ÄÀ» ¸¸µç´Ù. cellsColl.align='center'; if (childrenCollection.children.item(idx).type=='text') cellsColl.innerText=childrenCollection.children.item(idx).value; else cellsColl.innerText=childrenCollection.children.item(idx).innerText; } } </SCRIPT> <DIV id="parentObj" style="border:solid 1 red;text-align:center"><SPAN id=spanObj>¸ðü DIV (ID: parentObj)</SPAN><BR id="brObj"> ÅؽºÆ® ÀÔ·Â °³Ã¼ : <INPUT type="text" name="textObj" value="ÀÔ·Â ¹®Àå" size="8" contenteditable="false"> <DIV id="childObj"><P id="paraObj">DIV ¼ÓÀÇ ¹®´Ü °³Ã¼</P><SPAN id=span1Obj>ÀÚ½Ä ¼ÓÀÇ ÀÚ½Ä SPAN</SPAN></DIV> <BUTTON name="buttonObj" onclick="alert('´ÜÃ߸¦ Ŭ¸¯Çß´Ù');">´ÜÃß °³Ã¼</BUTTON> <HR id="hrObj"> <BUTTON name="button2Obj" onclick="getCollections();this.disabled=true;" style="cursor:hand">Ä÷º¼Ç ¾ò±â ´ÜÃß</BUTTON> </DIV> <TABLE id="tableObj" border="1" width="600" alt="ÀÚ½Ä ¸ñ·Ï °á°ú"> <TR><TH>index</TH><TH>ÀÚ½Ä °³Ã¼</TH><TH>id</TH><TH>¸ðü °³Ã¼</TH><TH>°³Ã¼ ³»¿ë</TH></TR> </TABLE>