ÁöÁ¤µÈ ű×ÀÇ ¿¤·¹¸àÆ®¸¦ »ý¼ºÇÑ´Ù.
¹Ýȯ°ª oVal´Â »õ·ÎÀÌ »ý¼ºµÈ ¿¤·¹¸àÆ®¸¦ ¹ÝȯÇÑ´Ù.
IE4.0¿¡¼´Â img,area¿Í Option °³Ã¼¸¸ »õ·ÎÀÌ »ý¼ºÇÒ ¼ö ÀÖ¾ú´Ù. IE5¿¡¼´Â frame°ú iFrameÀ» Á¦¿ÜÇÏ°í ¸ðµç ¿¤·¹¸àÆ®¸¦ ÇÁ·Î±×·¥ÀûÀ¸·Î »ý¼ºÇÒ ¼ö ÀÖ°Ô µÇ¾ú´Ù. ¶ÇÇÑ ÀÌ »ý¼ºµÈ ¿¤·¹¸àÆ®ÀÇ ¼Ó¼ºµéµµ ÇÁ·Î±×·¥ÀûÀ¸·Î Àбâ/¾²±â°¡ °¡´ÉÇÏ°Ô µÇ¾ú´Ù. »õ·Î¿î °³Ã¼¸¦ »ç¿ëÇϱâ Àü¿¡ ¹®¼³ª ÇØ´ç Ä÷¹¼Ç¿¡ ¸í½ÃÀûÀ¸·Î ±×µéÀ» Ãß°¡ÇÏ¿©¾ß ÇÑ´Ù. ÇöÀç ¹®¼¿¡ »õ·Î¿î ¿¤·¹¸àÆ®¸¦ »ðÀÔ»ç°íÀú ÇÒ ¶§´Â insertBefore ȤÀº appendChild ¸Þ¼µéÀ» »ç¿ëÇÏ¸é µÈ´Ù.
input ¿¤·¹¸àÆ®¸¦ »ý¼ºÇϱâ À§Çؼ createElement ¸Þ¼µå¸¦ »ç¿ëÇÒ ¶§´Â, ´ÙÀ½´Ü°è °úÁ¤À» ¼öÇàÇÏ¿©¾ß ÇÑ´Ù. ÀÌ°ÍÀÌ µðÆúÆ® input type ¼Ó¼ºÀ̹ǷΠcreateElement ¸Þ¼µå·Î ÀÔ·Â ÅؽºÆ® ¹Ú½º¸¦ »ý¼ºÇÑ´Ù. ´Ù¸¥ Á¾·ùÀÇ input ÀÔ·Â ¿¤·¹¸àÆ®¸¦ »ðÀÔÇϱâ À§Çؼ´Â ¸ÕÀú input¸¦ À§ÇÑ createElement¸¦ ÇÏ°í, ÄÚµåÀÇ ´ÙÀ½ ºÎºÐ¿¡ Àû´çÇÑ °ªÀÇ type ¼Ó¼ºÀ» ¼³Á¤ÇÑ´Ù.
¾ÖÆ®¸®ºäÆ®µéÀÌ ¸ðµç ¹®ÀÚ¿ÀÌ À¯È¿ÇÑ HTML ¹®ÀÚ¿ÀÌ µÇµµ·Ï sTag¿¡ Æ÷Ç﵃ ¼ö ÀÖ´Ù. À̸§ ¼Ó¼ºÀ» ÁöÁ¤ÇÏ·Á¸é ·±Å¸ÀÓ¿¡ createElement ¸Þ¼µå·Î »ý¼ºµÈ °³Ã¼¿¡ nameÀ» Æ÷ÇÔ ½Ãų ¼ö ÀÖ´Ù.
¿¤·¹¸àÆ®°¡ »ý¼ºµÉ ¶§ sTag¿¡ ¾ÖÆ®¸®ºäÆ®µéÀÌ Æ÷ÇԵǾî¾ß ÇÏ°í, reset ¸Þ¼µå³ª type ¾ÖÆ®¸®ºäÆ® °ª resetÀÎ BUTTONÀ» »ç¿ëÇÏ¿© Àç¼³Á¤µÈ´Ù.
°³Ã¼ | script | IE |
---|
ÀÌ ¸Þ¼µå´Â (¿µ¾î)DOM Level 1(Document Object Model Level 1)¿¡¼ Á¤ÀǵǾú´Ù.
createElement ¸Þ¼µå¸¦ »ç¿ëÇÏ¿© ź·ÂÀûÀ¸·Î À¥ÆäÀÌÁö ³»¿ëÀ» º¯°æ½ÃŲ´Ù.
<SCRIPT> function fnCreate(){ oData.innerHTML=''; var oOption=oSel.options[oSel.selectedIndex]; if(oOption.text.length>0){ var aElement=document.createElement(oOption.text); eval('aElement.'+oOption.value+'="'+oText.value+'"'); if(oOption.text=='A') aElement.href='javascript:alert("A link.")'; } oData.appendChild(aElement); str='oData.children.length='+oData.children.length+'<BR>'; str+='oData.children[0].nodeName='+oData.children[0].nodeName+'<BR>'; str+='oData.children[0].value='+oData.children[0].value+'<BR>'; str+='oData.children[0].innerText='+oData.children[0].innerText+'<BR>'; str+='oData.children[0].href='+oData.children[0].href+'<BR>'; str+='<BR>'; for (i=0;i< oSel.options.length;i++){ str+=i+'] oSel.options['+i+'].text='+oSel.options[i].text; str+=', oSel.options['+i+'].value='+oSel.options[i].value+'<BR>'; } str+='<BR>'; for (i=0;i< oText.options.length;i++){ str+=i+'] oText.options['+i+'].text='+oText.options[i].text+'<BR>'; } showA.innerHTML=str; } </SCRIPT> Á¦¾î ¼±Åà : <SELECT id="oSel" onchange="fnCreate()"> <OPTION value="innerText">A <OPTION value="value"><INPUT type="button"> </SELECT><BR> ÅؽºÆ® ¼±Åà : <SELECT id=oText onchange="fnCreate()"> <OPTION> <OPTION value="ÅؽºÆ®">ÅؽºÆ® <OPTION value="±ä ¹®ÀÚ¿">±ä ¹®ÀÚ¿</SELECT> <DIV id="oData" style="border:solid 1 blue">°á°ú Ç¥½Ãâ</DIV> <DIV id=showA style="border:solid 1 blue">°á°ú Ç¥½Ãâ</DIV>
"´ÜÃß1", "´ÜÃß2"¶ó´Â °ªÀ¸·Î ´ÜÃß ¿¤·¹¸àÆ®°¡ »ý¼ºµÈ ÈÄ ¹®¼ °èÅë¿¡ µÎ¹ø »ðÀԵȴÙ.
createElement ¸Þ¼µå ¼Ó¿¡¼ HTML ÅÂ±× ¹®ÀÚ¿¸¦ »ç¿ëÇÏ¿© ¿¤·¹¸àÆ®ÀÇ ¸ðµç ¾ÖÆ®¸®ºäÆ®¸¦ ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù.
<DIV id=example2>
<FORM id="fname">
<INPUT type="button" id="but1" onclick="makeButton()" value="´ÜÃ߸¦ »ý¼ºÇÔ"><BR>
<INPUT type="button" onclick="alert (example2.outerHTML)" value="ÀÌ ¿¹Á¦ÀÇ HTML ³»¿ë º¸±â">
</FORM>
<SCRIPT>
function makeButton(){
newElem=document.createElement('<INPUT type="button" name="button1" value="´ÜÃß1">');
fname.insertBefore(newElem,fname.but1);
newElem=document.createElement('<INPUT type="button" name="button2" value="´ÜÃß2">');
fname.insertBefore(newElem,fname.but1);
// document.body.insertBefore(newElem); ¹®¼ÀÇ Á¦ÀÏ µÚ¿¡ »ðÀÔÇÏ·Á¸é...
}
</SCRIPT>
</DIV>