Document Object
ÀÌ ¹ø ÆäÀÌÁö¿¡¼´Â Document °´Ã¼°¡ °¡Áö°í ÀÖ´Â Property(ÇÏÀ§ °´Ã¼)µé¿¡ ´ëÇØ¼ ¾Ë¾Æ º¸µµ·Ï ÇϰڽÀ´Ï´Ù. Document °´Ã¼ÀÇ PropertyµéÀº ÁÖ·Î ¹®¼(Document)³»ÀÇ Link, Anchor, Image, Title µî ¹®¼¿¡ »ç¿ëµÈ Tag¿¡ ´ëÇÑ ¹®¼ ³»ºÎÀûÀÎ Á¤º¸¿Í ¹®¼ÀÇ domain, Url µî ¿ÜºÎÀûÀÎ Á¤º¸¿Í Á¤º¸ µéÀ» ¾Ë¾Æ º¸´Âµ¥ »ç¿ëµÇ¸ç ¾Æ·¡ÀÇ ±×¸²¿¡¼ º¸´Â ¹Ù¿Í °°ÀÌ document °´Ã¼¿¡´Â ¿©·¯ °³ÀÇ ÇÏÀ§ °´Ã¼µéÀÌ ÀÖÀ¸¸ç, Layer¿Í PluginÀº Netscape¿¡¼¸¸ Àû¿ëµË´Ï´Ù.
*** Property¿Í Method À̸§Àº ´ë¼Ò¹®ÀÚ¸¦ Çо¾¸® ±¸ºÐ(Case-sensitive)ÇÕ´Ï´Ù.
| Document Object Properties |
| anchors |
¹®¼¿¡ Æ÷ÇÔµÈ anchor element collection return |
| applets |
applet ¿¡ Æ÷ÇÔµÈ ¸ðµç element collection return |
| body |
body ¶Ç´Â frameset return |
| cookie |
¹®¼ÀÇ ÄíŰ °ª return |
| domain |
¹®¼ÀÇ µµ¸ÞÀÎ À̸§ return |
| forms |
¹®¼ÀÇ form collection¿¡ Æ÷ÇÔµÈ ¸ðµç element return |
| images |
¹®¼¿¡ Æ÷ÇÔµÈ ¸ðµç image element collection return |
| links |
¹®¼³»ÀÇ href attribute·Î ÁöÁ¤µÈ ¸ðµç anchor collection return |
| referrer |
ÇöÀç ¹®¼ÀÇ ¸µÅ©°¡ ÀÖ´Â ¹®¼ÀÇ URL °ª return |
| title |
¹®¼ÀÇ title return ¶Ç´Â ÁöÁ¤ |
| URL |
¹®¼ÀÇ URL °ª return |
Document ObjectÀÇ Property ¿¹Á¦ <html>
<head>
<title>Document ObjectÀÇ Property</title>
<style type="text/css">
<!--
img {border:1px solid royalblue;}
-->
</style>
</head>
<body style="background-color:buttonface;">
<fieldset style="padding:10px;">
<legend>Document ObjectÀÇ Property</legend>
<a name="first">first</a><br />
<a name="second">second</a><br />
<a name="third">third</a><br />
<form name="frm1"><input value="form1" /></form><br />
<form name="frm2"><input value="form2" /></form>
<img src="../../images/icon/ico_doc.gif" alt="ico_doc (1K)" /><br /><br />
<img src="../../images/icon/ico_doc_new.gif" alt="ico_doc_new (1K)" /><br /><br />
<img src="../../images/icon/ico_explanation.gif" alt="ico_explanation (1K)" /><br /><br />
<a href="#first">link 1</a><br />
<a href="#second" id="link2">link 2</a><br />
<a href="#third">link 3</a><br />
</fieldset><br /><br />
<script type="text/javascript">
<!--
document.write("¹®¼ÀÇ ¹è°æ»ö : " + document.body.style.backgroundColor + "<br />")
document.write("¹®¼ÀÇ Á¦¸ñ : " + document.title + "<br />")
document.write("¹®¼¿¡ Æ÷ÇÔµÈ anchorÀÇ °¹¼ö : " + document.anchors.length + "°³<br />")
document.write("¹®¼¿¡ Æ÷ÇÔµÈ Ã¹¹øÂ° anchorÀ̸§ : " + document.anchors[0].name + "<br/>")
document.write("¹®¼¿¡ Æ÷ÇÔµÈ linkÀÇ °¹¼ö : " + document.links.length + "°³<br />")
document.write("¹®¼¿¡ Æ÷ÇÔµÈ µÎ¹øÂ° linkÀÇ id : " + document.links[1].id + "<br />")
document.write("¹®¼¿¡ Æ÷ÇÔµÈ imageÀÇ °¹¼ö : " + document.images.length + "°³<br />")
document.write("¹®¼ÀÇ URL : " + document.URL + "<br />")
document.write("¹®¼¿¡ Æ÷ÇÔµÈ formÀÇ °¹¼ö : " + document.forms.length + "°³<br />")
document.write("¹®¼ÀÇ Ã¹ ¹øÂ° formÀÇ name °ª : " + document.forms[0].name + "<br />")
document.write("¹®¼ÀÇ µÎ ¹øÂ° formÀÇ name °ª : " + document.forms[1].name + "<br />")
document.write("ÀÌ ¹®¼ÀÇ Link°¡ ÀÖ´Â fileÀÇ URL : " + document.referrer + "<br />")
document.write("¹®¼ÀÇ cookie °ª : " + document.cookie + "<br />")
document.write("¹®¼ÀÇ Domain name : " + document.domain + "<br />")
// -->
</script>
</body>
</html>
Document object ÀÇ Method
¾î¶² Object¿¡ °ü·ÃÇØ¼ Method ¶ó´Â°Ô ¿©·¯°³ ÀÖ½À´Ï´Ù. Method¶õ ´Ü¾îÀÇ ¶æ ó·³ ±× ÇØ´ç Object¸¦ ´Ù·ç´Â ¹æ¹ýÀÌ µÇ°Ú½À´Ï´Ù. ±×·¯¹Ç·Î Document Object¿¡ °ü·ÃµÈ Method´Â °ð Document Object¸¦ ´Ù·ç´Â ¹æ¹ýÀ¸·Î¼ ÀÌ·¯ÇÑ MethodµéÀº ºê¶ó¿ìÀú°¡ Áö¿øÇÏ°Ô µË´Ï´Ù. ¾Æ·¡ÀÇ Ç¥´Â Document Object¸¦ ´Ù·ç´Â Method°¡ µÇ°Ú½À´Ï´Ù.
| Document Object Methods |
| close() |
document.open() method·Î ¿¸° ¹®¼¸¦ ´Ý´Â´Ù. |
| getElementById(ID) |
ÁöÁ¤µÈ ID ¸¦ °¡Áø element return |
| getElementsByName(name) |
ÁöÁ¤µÈ name ¸¦ °¡Áø element return |
| open() |
»õ ¹®¼¸¦ ¿¬´Ù. |
| write(string) |
¹®¼¿¡ ¹®ÀÚ¿À» Ãâ·ÂÇÑ´Ù. |
| writeln(string) |
¹®¼¿¡ ¹®ÀÚ¿ blockÀ» Ãâ·ÂÇÑ´Ù. |
getElementById("ID") & getElementsByName("name") Method <html>
<head>
<script type="text/javascript">
<!--
function getElement()
{
var doc=document.getElementById("myPara")
alert("³ªÀÇ À̸§Àº " + doc.tagName + " element ÀÔ´Ï´Ù. ")
}
function getName()
{
var doc=document.getElementsByName("myName")
alert("¸ðµÎ " + doc.length + " °³ ÀÔ´Ï´Ù. ")
}
//-->
</script>
</head>
<body>
<button id="myPara" onclick="getElement()">
Ŭ¸¯ÇÏ¸é ³ªÀÇ Element À̸§ÀÌ ³ª¿É´Ï´Ù.
</button><br />
<input name="myName" /><br />
<input name="myName" /><br />
<input name="myName" /><br />
<button onclick="getName()">Ŭ¸¯Çϸé ElementÀÇ °¹¼ö°¡ ³ª¿É´Ï´Ù.</button>
</body>
</html>