°³Ã¼ÀÇ ¾ÖÆ®¸®ºäÆ®(¼Ó¼º)µéÀÇ ¹è¿­º¯¼ö Ä÷º¼ÇÀ» ¹ÝȯÇÏ°í ÂüÁ¶ÇÑ´Ù.

Àμö
: (°³Ã¼)
ÇʼöÀûÀÎ ¿ä¼ÒÀÌ°í Ä÷º¼ÇÀ» Æ÷ÇÔÇÏ´Â ¸ðü °³Ã¼ÀÌ´Ù.

cVal : (Ä÷º¼Ç)
¼±ÅÃÀûÀÎ ¿ä¼ÒÀÌ°í °ªÀº Ä÷º¼ÇÀ» ³ªÅ¸³»´Â °³Ã¼ÀÌ´Ù.

oVal : (°³Ã¼)
¼±ÅÃÀûÀÎ ¿ä¼ÒÀÌ°í °ªÀº Ä÷º¼ÇÀÇ ÇÑ°³ÀÇ ¿¤·¹¸àÆ® °³Ã¼ÀÌ´Ù.

index : (Á¤¼ö/¹®ÀÚ¿­)
ÇʼöÀûÀÎ ¿ä¼ÒÀÌ°í °ªÀº Ä÷º¼ÇÀÇ Àμö·Î ÇÑ°³ÀÇ ¿¤·¹¸àÆ® °³Ã¼¸¦ ÂüÁ¶ÇÒ ¼ö ÀÖ°í ¹è¿­º¯¼öÀÇ ±ÔÄ¢¿¡µû¶ó 0ºÎÅÍ ½ÃÀÛÇÏ°í Á¦ÀÏ ¸¶Áö¸· Àμö´Â ±æÀ̺¸´Ù 1 ÀÛ´Ù.

Ư±â

IE6ºÎÅÍ attributes Ä÷º¼Ç¿¡ °³Ã¼ÀÇ expando ¼Ó¼ºµéÀÌ Æ÷ÇԵǾú´Ù. ÀÌÀü ¹öÀü¿¡¼­ °³Ã¼ÀÇ expando ¼Ó¼º¿¡ Á¢¼ÓÇϱâ À§Çؼ­´Â for...in¸¦ »ç¿ëÇÑ´Ù.

attributes Ä÷º¼Ç¿¡¼­´Â style °³Ã¼¸¦ »ç¿ëÇÒ ¼ö ¾ø°í, °³Ã¼ÀÇ È®½ÇÇÑ ½ºÅ¸ÀϽ¬Æ®¸¦ ¹ÝȯÇϱâ À§Çؼ­´Â °³Ã¼ÀÇ style ¼Ó¼ºÀÇ cssText¼Ó¼ºÀ» »ç¿ëÇÑ´Ù.

all°ú children Ä÷º¼Çµî ´Ù¸¥ DHTML Ä÷º¼Çµé°ú´Â ´Ù¸£°Ô attributes Ä÷º¼Ç °íÁ¤Àû(static)ÀÌ´Ù. °³Ã¼ÀÇ ¼Ó¼ºÀ» º¯°æ½ÃÄѵµ ÀÚµ¿ÀûÀ¸·Î ±× °³Ã¼ÀÇ ÂüÁ¶ÇÏ´Â attributes Ä÷º¼Ç¿¡ ¹Ý¿µµÇÁö ¾Ê´Â´Ù.

Àû¿ë
°³Ã¼scriptHTML±Ô°ÝIE
ÂüÁ¶

ÀÌ Ä÷º¼ÇÀº (¿µ¹®)DOM Level 1(W3C Document Object Model)¿¡ Á¤ÀǵǾú´Ù.


¼³¸íÀ» À§ÇÑ ¿¹Á¦

attributes ¿¹Á¦

length ¼Ó¼º IE
¢¡ Ä÷º¼ÇÀÇ ±æÀ̸¦ ¹ÝȯÇϰųª ÁöÁ¤ÇÑ´Ù.
¹®¹ý: [iVal=]object.attributes.length
ÄÚµå: document.write(oObj.length); °á°ú:

getNamedItem ¸Þ¼­µå IE
¢¡ Ä÷º¼Ç¿¡¼­ name ¼Ó¼º À̸§À¸·Î ÁöÁ¤ÇÑ ¾ÖÆ®¸®ºäÆ®¸¦ ¹ÝȯÇÑ´Ù.
¹®¹ý: [oVal=].getNamedItem('sVal')
ÄÚµå: document.write(oObj.getNamedItem('type').nodeName+' | '+oObj.getNamedItem('type').specified+' | '+oObj.getNamedItem('type').nodeValue) °á°ú:
item ¸Þ¼­µå IE
¢¡ À妽º·Î Ä÷º¼ÇÀÇ ÇÑ°³ÀÇ °³Ã¼¸¦ ¹ÝȯÇÑ´Ù.
¹®¹ý: [oVal=].item('iVal')
ÄÚµå: document.write(oObj.item(0).name) °á°ú:
removeNamedItem ¸Þ¼­µå IE
¢¡ Ä÷º¼Ç¿¡¼­ name ¼Ó¼º À̸§À¸·Î ÁöÁ¤ÇÑ ¾ÖÆ®¸®ºäÆ®¸¦ °ª°ú ÇÔ²² Á¦°ÅÇÑ´Ù.
¹®¹ý: .removeNamedItem('sVal')
ÄÚµå: if (oObj.getNamedItem('name')) document.write(oObj.getNamedItem('name').nodeName+' | '+oObj.getNamedItem('name').specified+' | '+oObj.getNamedItem('name').nodeValue) °á°ú:
ÄÚµå: oObj.removeNamedItem('name');if (oObj.getNamedItem('name')) document.write(oObj.getNamedItem('name').nodeName+' | '+oObj.getNamedItem('name').specified+' | '+oObj.getNamedItem('name').nodeValue) °á°ú:
setNamedItem ¸Þ¼­µå IE
¢¡ Ä÷º¼Ç¿¡ name ¼Ó¼º À̸§À¸·Î ÁöÁ¤ÇÑ ¾ÖÆ®¸®ºäÆ®¸¦ ¼³Á¤ÇÑ´Ù.
¹®¹ý: [oVal=].setNamedItem('sVal')
ÄÚµå: newOne=document.createAttribute('type');newOne.value='newAttrib';oObj.setNamedItem(newOne);;document.write(oObj.getNamedItem('type').nodeName+' | '+oObj.getNamedItem('type').specified+' | '+oObj.getNamedItem('type').nodeValue) °á°ú:

Ä÷º¼Ç ¿¹Á¦

SPAN Attributes º¸±â U Attributes º¸±â A Attributes º¸±â
  • Ç׸ñ 1
  • Ç׸ñ2
DIV Attributes º¸±â
°á°ú Ç¥½Ãâ
<SCRIPT>
function showAttribs(elemObj){
  str='<TABLE width=100%><TR><TD width=50%>elemObj.nodeName='+elemObj.nodeName;
  str+=' (id=<FONT color=blue><B>'+elemObj.id+'</B></FONT>)<BR>';
  colAttribs=elemObj.attributes;
  for (i=0;i< colAttribs.length;i++){
    if(!(i%Math.ceil((colAttribs.length)/2))&&i){
      str+='</TD><TD width=50%>';
      str+='elemObj.attributes.length=<FONT color=red><B>'+elemObj.attributes.length+'</B></FONT><BR>';
    }
    atr1=colAttribs[i];
    str+='<FONT color=silver>['+i+']</FONT> <FONT color=blue>'+atr1.nodeName+'</FONT>=';
    str+='<FONT color=teal>'+atr1.nodeValue+'</FONT> '
    str+='(<FONT color=gray>'+(atr1.specified ? '<FONT color=blue><B>true</B></FONT>':'false')+'</FONT>)<BR>';
  }
  str+='</TD></TR></TABLE>';
  showA.innerHTML=str;
}
</SCRIPT>
<DIV style="border:solid 1 green;padding=5" title="°³Ã¼¸¦ Ŭ¸¯Çغ¸¶ó.">
<SPAN onclick="showAttribs(this)" id="span1" style="border:solid 1 blue">SPAN Attributes º¸±â</SPAN>
<U onclick="showAttribs(this)" id="u1" style="border:solid 1 blue">U Attributes º¸±â</U>
<A onclick="showAttribs(this)" id="a1" href="#exampleJump" style="border:solid 1 blue">A Attributes º¸±â</A>
<UL><LI onclick="showAttribs(this)" id="li1" style="border:solid 1 blue">Ç׸ñ 1
<LI onclick="showAttribs(this)" id="li2" style="border:solid 1 blue">Ç׸ñ2</UL>
<DIV onclick="showAttribs(this)" id="div1" style="border:solid 1 blue">DIV Attributes º¸±â</DIV>
<BUTTON onclick="showAttribs(this)" id="but1">´ÜÃß Attributes º¸±â</BUTTON>
</DIV>
<DIV id=showA>°á°ú Ç¥½Ãâ</DIV>