Tel. 042-353-2371

ÆòÀÏ ¿ÀÀü 9½Ã ~ ¿ÀÈÄ 7½Ã
±â¾÷ÀºÇà

010-8649-6758

¿¹±ÝÁÖ:Á¦ÁÖ»ç¶û(¼ÛÁø¾Æ)
JAVASCRIPT
Ȩ > ȨÆäÀÌÁöÁ¦ÀÛ±³½Ç > JAVASCRIPT

Ä«Å×°í¸® Object
Á¦¸ñ Window > event Object
ÀÛ¼ºÀÚ freewebkorea
ÀÛ¼ºÀÏÀÚ 2009-12-09
Á¶È¸¼ö 1735

event Object

event Property´Â JavaScriptÀÇ Keyboard event, Mouse event µî¿¡ ÀÇÇØ ¹ß»ýÇÏ´Â mouseÀÇ ÁÂÇ¥¶óµçÁö, ¾î¶² Keyboard°¡ ´­·ÁÁ³´ÂÁö ¶Ç´Â event°¡ ¹ß»ýÇÏ´Â object¿¡ ´ëÇÑ Á¤º¸µéÀ» return ÇØ ÁÝ´Ï´Ù.
event Object Property
altKey alt Key°¡ ´­·Á Á³´ÂÁöÀÇ ¿©ºÎ return (´­·ÁÁ³À¸¸é true, ¾Æ´Ï¸é false)
button
mouse buttonÀÌ ´­·ÁÁø »óÅÂ return
0 ¾Æ¹« button µµ ¾È ´­·ÁÁø »óÅÂ
1 ¿ÞÂÊ buttonÀÌ ´­·ÁÁø »óÅÂ
2 ¿À¸¥ÂÊ buttonÀÌ ´­·ÁÁø »óÅÂ
3 ¿ÞÂʰú ¿À¸¥ÂÊ buttonÀÌ µ¿½Ã¿¡ ´­·ÁÁø »óÅÂ
4 °¡¿îµ¥ buttonÀÌ µ¿½Ã¿¡ ´­·ÁÁø »óÅÂ
5 ¿ÞÂʰú °¡¿îµ¥ buttonÀÌ µ¿½Ã¿¡ ´­·ÁÁø »óÅÂ
6 ¿À¸¥Âʰú °¡¿îµ¥ buttonÀÌ µ¿½Ã¿¡ ´­·ÁÁø »óÅÂ
7 3°³ÀÇ buttonÀÌ µ¿½Ã¿¡ ´­·ÁÁø »óÅÂ
clientX â Å׵θ®¿Í scrollbar ¸¦ Á¦¿ÜÇÑ ¿µ¿ª¿¡¼­ÀÇ mouseÀÇ X »ó´ë ÁÂÇ¥
clientY â Å׵θ®¿Í scrollbar ¸¦ Á¦¿ÜÇÑ ¿µ¿ª¿¡¼­ÀÇ mouseÀÇ Y »ó´ë ÁÂÇ¥
ctrlKey ctrl Key°¡ ´­·Á Á³´ÂÁöÀÇ ¿©ºÎ return (´­·ÁÁ³À¸¸é true, ¾Æ´Ï¸é false)
keyCode Keyboard ¹®ÀÚÀÇ Unicode(ISO-Latin-1 character set) °ª return
offsetX event °¡ ¹ß»ýÇÏ´Â box(object) ÁÂÃø »ó´Ü¿¡ ´ëÇÑ mouse cursorÀÇ X »ó´ë ÁÂÇ¥
offsetY event °¡ ¹ß»ýÇÏ´Â box(object) ÁÂÃø »ó´Ü¿¡ ´ëÇÑ mouse cursorÀÇ Y »ó´ë ÁÂÇ¥
screenX »ç¿ëÀÚ ¸ð´ÏÅÍ¿¡ ´ëÇÑ mouse cursorÀÇ X »ó´ë ÁÂÇ¥
screenY »ç¿ëÀÚ ¸ð´ÏÅÍ¿¡ ´ëÇÑ mouse cursorÀÇ Y »ó´ë ÁÂÇ¥
shiftKey shift Key°¡ ´­·Á Á³´ÂÁöÀÇ ¿©ºÎ return (´­·ÁÁ³À¸¸é true, ¾Æ´Ï¸é false)
srcElement event°¡ ¹ß»ýÇÏ´Â element return
x »ó´ë À§Ä¡·Î positioning (position:relative;) µÈ 1 ´Ü°è »óÀ§ element ¿¡ ´ëÇÑ mouse cursorÀÇ x »ó´ë ÁÂÇ¥
y »ó´ë À§Ä¡·Î positioning (position:relative;) µÈ 1 ´Ü°è »óÀ§ element ¿¡ ´ëÇÑ mouse cursorÀÇ y »ó´ë ÁÂÇ¥




shiftKey, ctrlKey, altKey

shiftKey, ctrlKey, altKey °¡ ´­·ÁÁø »óÅÂÀÎÁö ¾Æ´ÑÁö¸¦ true(1), false(0) °ªÀ¸·Î return ÇØ ÁÝ´Ï´Ù.
¿¹Á¦

<html>
<head>
<title>shiftKey, ctrlKey, altKey</title>
<script type="text/javascript">
<!--
function shiftKeyPressed(){
if (event.shiftKey==1){
alert("shift key °¡ ´­·ÁÁø »óÅÂÀÔ´Ï´Ù.!")
}
else
{
alert("shift key °¡ ´­·ÁÁöÁö ¾ÊÀº »óÅÂÀÔ´Ï´Ù.!")
}
}

function ctrlKeyPressed(){
if (event.ctrlKey==1){
alert("ctrl key °¡ ´­·ÁÁø »óÅÂÀÔ´Ï´Ù.!")
}
else
{
alert("ctrl key °¡ ´­·ÁÁöÁö ¾ÊÀº »óÅÂÀÔ´Ï´Ù.!")
}
}

function altKeyPressed(){
if (event.altKey==1){
alert("alt key °¡ ´­·ÁÁø »óÅÂÀÔ´Ï´Ù.!")
}
else
{
alert("alt key °¡ ´­·ÁÁöÁö ¾ÊÀº »óÅÂÀÔ´Ï´Ù.!")
}
}
// -->
</script>
</head>
<body>
<div style="width:100%; height:150px;background-color:tomato;"
onmousedown="shiftKeyPressed();">shift Key¸¦ ´©¸£°í Ŭ¸¯ ¶Ç´Â ´©¸£Áö ¾Ê°í Ŭ¸¯ÇØ º¸¼¼¿ä.</div>
<div style="width:100%; height:150px;background-color:royalblue;"
onmousedown="ctrlKeyPressed();">ctrl Key¸¦ ´©¸£°í Ŭ¸¯ ¶Ç´Â ´©¸£Áö ¾Ê°í Ŭ¸¯ÇØ º¸¼¼¿ä.</div>
<div style="width:100%; height:150px;background-color:palegreen;"
onmousedown="altKeyPressed();">alt Key¸¦ ´©¸£°í Ŭ¸¯ ¶Ç´Â ´©¸£Áö ¾Ê°í Ŭ¸¯ÇØ º¸¼¼¿ä.</div>
</body>
</html>


ÄÚµå ½ÇÇà Çϱâ



button

½ÇÇà ÇÑ ÈÄ¿¡ ¿À¸¥ÂÊ ¹öưÀ» ´­·¯ º¸°í event.button == 2 ¿¡¼­ 2¸¦ 1 ~ 7 »çÀÌÀÇ ¼ö¸¦ ¹Ù²Ù¾î ÀÔ·ÂÇÏ°í ½ÃÇèÇØ º¸¼¼¿ä... µ¿½Ã¿¡ ´©¸£´Â °æ¿ì ¹öư 2°³¸¦ °°Àº ¼ø°£¿¡ ´­·¯¾ß µÈ´Ù´Â ¶æÀÌ ¾Æ´Ï¶ó 2°³°¡ ´­·Á Áö±â¸¸ ÇÏ¸é µÈ´Ù´Â ¶æÀÔ´Ï´Ù. ½Ã°£ ¸ÂÃç¼­ °°ÀÌ ´©¸¦¶ó°í ¾Ö¾²Áö ¸¶½ÃÁ®...
ÀÔ·Â

<html>
    <head>
        <title>button</title>
    <script type="text/javascript">
    <!--
    function button_2(){
    if (event.button == 2)
    {alert ("¿À¸¥ÂÊ button À» ´­·¶½À´Ï´Ù.")}
    }
    // -->
    </script>
    </head>
    <body onmousedown="button_2();">
        ¿À¸¥ÂÊ ¹öưÀ» ´©¸£½ÃÁ®... ±×¸®°í event.button == 2 ¿¡¼­
        2¸¦ 1 ~ 7 »çÀÌÀÇ ¼ö¸¦ ¹Ù²Ù¾î ÀÔ·ÂÇÏ°í ½ÃÇèÇØ º¸¼¼¿ä...
    </body>
</html>
ÄÚµå ½ÇÇà Çϱâ



srcElement, keyCode

srcElement´Â event°¡ ¹ß»ýÇÏ´Â ¹°Ã¼(object)ÀÇ Á¤º¸¸¦ return Çϰí, keyCode ´Â Keyboard ¹®ÀÚÀÇ Unicode °ª(¼ýÀÚ)À» return ÇØ ÁÝ´Ï´Ù.
ÀÔ·Â

<html>
    <head>
        <title>srcElement, keyCode</title>
    <script type="text/javascript">
    <!--
    function whichButton(){
    alert(event.keyCode)
    }
    
    function whichElement(){
    tag_Name = event.srcElement.tagName
    tag_ID = event.srcElement.id
    alert("³ª´Â " + tag_Name + " element À̰í, id´Â " + tag_ID + " ÀÔ´Ï´Ù.")
    }
    // -->
    </script>
    </head>
    <body id="main" onkeyup="whichButton()" onclick="whichElement()">
        ¸ÕÀú Ŭ¸¯À» ÇÑ ÈÄ¿¡ Keyboard¸¦ ´­·¶´Ù ¶¼¸é Unicode °ªÀÌ alert â¿¡ ³ª¿À°Ô µË´Ï´Ù.<br />
        Áï, â¿¡ focus°¡ µé¾î ¿Â »óÅ¿¡¼­¸¸ OnKeyUp ÀÌ ¸Ô½À´Ï´Ù.
        <p id="para">p ÀÔ´Ï´Ù.</p>
        <div id="box">div ÀÔ´Ï´Ù.</div>
        <span id="inline">span ÀÔ´Ï´Ù.</span><br />
        <button type="button" id="btn">button ÀÔ´Ï´Ù.</button>
    </body>
</html>
ÄÚµå ½ÇÇà Çϱâ



offsetX, offsetY

offsetX, offsetY ´Â Àý´ëÀ§Ä¡(absolute)·Î positioning µÈ boxÀÇ ÁÂÃø »ó´ÜÀ» ±âÁØÀ¸·Î ÇÑ mouseÀÇ X¿Í YÀÇ ÁÂÇ¥¸¦ return ÇØ ÁÝ´Ï´Ù.
ÀÔ·Â

<html>
<head>
<title>offsetX, offsetY</title>
<script type="text/javascript">
<!--
function offsetCoords() {
var offsetInfo = ""
offsetInfo = "offsetX : " + window.event.offsetX + "r"
offsetInfo += "offsetY : " + window.event.offsetY + "r"
alert(offsetInfo);
}

function offsetStatus(){
window.status = "X = " + window.event.offsetX + " Y = " + window.event.offsetY
}
// -->
</script>
</head>
<body onmousemove="offsetStatus()" ondblclick="offsetCoords();">
mouse cursor°¡ box ¹Û¿¡ ÀÖÀ» ¶§´Â âÀÇ ÁÂÃø »ó´ÜÀ» ±âÁØÀ¸·Î ÇÑ »ó´ëÁÂÇ¥°¡ status bar¿¡ Ç¥½ÃµÇ°í
bouble Click Çϸé alert â¿¡ x, y ÁÂÇ¥°¡ ¶ß°í, box ¼ÓÀ¸·Î µé¾î°¡¸é boxÀÇ ÁÂÃø »ó´ÜÀ» ±âÁØÀ¸·Î ÇÑ »ó´ëÁÂÇ¥°¡ Ç¥½ÃµÇ°í, click Çϸé alert â¿¡ x, y ÁÂÇ¥°¡ Ç¥½Ã µË´Ï´Ù.
<DIV onclick="offsetCoords();" STYLE="width:200; height:200; background-color:gray; position:absolute; top:100; left:200; color:gold;">
ÀÌ DIV box´Â top:100px, left:300px À§Ä¡¿¡ position:absolute·Î positioning µÈ box ÀÔ´Ï´Ù.
</DIV>
</body>
</html>


ÄÚµå ½ÇÇà Çϱâ