select °³Ã¼ÀÇ ¼±ÅÃµÈ OptionÀÇ À妽º(index)¸¦ ¹ÝȯÇϰųª ¼³Á¤ÇÑ´Ù.

Àμö
: (¼Ó¼º Á¤¼ö°ª)
¼Ó¼º°ªÀº select°³Ã¼ÀÇ ¼±ÅÃµÈ OptionÀÇ À妽º(index)¸¦ ³ªÅ¸³»´Â Á¤¼ö°ªÀÌ´Ù.

ÀÌ ¼Ó¼ºÀº Àбâ/¾²±âÀÌ¸ç µðÆúÆ®°ªÀº ¾ø´Ù.

Ư±â

select °³Ã¼ÀÇ OptionµéÀº űװ¡ ³ª¿À´Â ¼ø¼­´ë·Î Àε¦½ÌµÇ¾î Á¦ÀÏ ¸ÕÀú °ÍÀÌ index 0ÀÌ´Ù. selectedIndex ¼Ó¼ºÀ» À¯È¿¾È °ªÀ¸·Î ¼³Á¤Çϸé Áï½Ã select °³Ã¼°¡ ¾÷µ¥ÀÌÆ®µÇ¾î µð½ºÇ÷¹À̵ȴÙ.

select °³Ã¼°¡ ¼±ÅÃµÈ Ç׸ñÀÌ ¾øÀ¸¸é selectedIndex ¼Ó¼ºÀº -1À» ¹ÝȯÇÑ´Ù. selectedIndex ¼Ó¼ºÀ» ¼³Á¤ÇÏ¸é ±âÁ¸ ¼±ÅÃÇ׸ñÀÇ ¼±ÅÃÀº Á¦°ÅµÇ°í ¾÷µ¥ÀÌÆ®µÈ´Ù.

selectedIndex ¼Ó¼ºÀº select °³Ã¼¿¡¼­ multiple ¾ÖÆ®¸®ºäÆ®°¡ ÁöÁ¤µÇÁö ¾ÊÀº »óÅ¿¡¼­ Çѹø¿¡ ÇÑ°³¸¸À» ¼±ÅÃÇϴµ¥ ¾ÆÁÖ À¯¿ëÇÏ°Ô »ç¿ëµÈ´Ù. select °³Ã¼¿¡¼­ multiple ¾ÖÆ®¸®ºäÆ®°¡ ÁöÁ¤µÇ¸é, selectedIndex ¼Ó¼ºÀº ¼±ÅÃµÈ Ç׸ñ ÁßÀÇ Á¦ÀÏ ¸ÕÀú °ÍÀÇ À妽º ¸¸À» ¹ÝȯÇÑ´Ù.

selected ¼Ó¼ºÀº multiple ¾ÖÆ®¸®ºäÆ®°¡ ¼³Á¤µÇ¾î select °³Ã¼µé¿¡¼­ ¿©·¯Ç׸ñ Áß ÇÑ°³ÀÌ»óÀ» ¼±ÅÃÇϴµ¥ À¯¿ëÇÏ´Ù. selected ¼Ó¼ºÀ¸·Î select °³Ã¼ÀÇ °³º° Ç׸ñÀÌ ¼±ÅõǾî Àִ°¡¸¦ Á¡°ËÇÏ¸é µÈ´Ù. ¶ÇÇÑ ÇÑ Ç׸ñÀ» ¼±ÅÃÇßÀ» ¶§ ÀÌ¹Ì ¼±ÅõǾú´ø selected ¼Ó¼ºÀÌ Á¦°ÅµÇÁö ¾ÊÀ¸¹Ç·Î ¿©·¯°³¸¦ Çѹø¿¡ ¼±ÅÃÇÒ ¼ö ÀÖ´Ù.

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

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


°á°ú Ç¥½Ãâ
<SCRIPT>
function showResult(obj){
  str='obj.selectedIndex='+obj.selectedIndex+'<BR>';
  str+='obj.options[obj.selectedIndex]='+obj.options[obj.selectedIndex]+'<BR>';
  str+='obj.options[obj.selectedIndex].value='+obj.options[obj.selectedIndex].value+'<BR>';
  str+='obj.options[obj.selectedIndex].text='+obj.options[obj.selectedIndex].text+'<BR>';
  str+='obj.options.multiple='+obj.options.multiple+'<BR>';
  showA.innerHTML=str;
}
</SCRIPT>
<SELECT onchange="showResult(this)">
<OPTION value="../object/jsList.html">°³Ã¼ ¸ñ·ÏÀÇ ÁÖ¼Ò</OPTION>
<OPTION value="../property/jsList.html">¼Ó¼º ¸ñ·ÏÀÇ ÁÖ¼Ò</OPTION>
<OPTION value="../method/jsList.html">¸Þ¼­µå ¸ñ·ÏÀÇ ÁÖ¼Ò</OPTION>
</SELECT>
<DIV id=showA>°á°ú Ç¥½Ãâ</DIV>