If you want something you've never had, you must be willing to do something you've never done!

Powered by Blogger.

Event Object 0

Cerita Semalam Aaz | 9:40 AM | ,



Event Object: What are the coordinates of the cursor?


<html>
<head>
<script type="text/javascript">
function show_coords(event) {
x=event.clientX
y=event.clientY
alert("X coords: " + x + ", Y coords: " + y)
}
</script>
</head>


<body onmousedown="show_coords(event)">
<p>Click in the document. An alert box will alert the x and y coordinates of the cursor.</p>
</body>


</html>




Event Object: What is the unicode of the key pressed?


<html>
<head>
<script type="text/javascript">
function whichButton(event) {
alert(event.keyCode)
}


</script>
</head>


<body onkeyup="whichButton(event)">
<p><b>Note:</b> Make sure the right frame has focus when trying this example!</p>
<p>Press a key on your keyboard. An alert box will alert the unicode of the key pressed.</p>
</body>


</html>



Event Object: Which element was clicked?

<html>
<head>
<script type="text/javascript">
function whichElement(e) {
var tarif (!e) var e = window.event if (e.target) targ = e.target
else if (e.srcElement) targ = e.srcElement if (targ.nodeType == 3) // defeat Safari bug
targ = targ.parentNode var tname tname=targ.tagName
alert("You clicked on a " + tname + " element.")
}
</script>
</head>

<body onmousedown="whichElement(event)">
<p>Click somewhere in the document. An alert box will alert the tag name of the element you clicked on.</p>

<h3>This is a header</h3>
<p>This is a paragraph</p>
<img border="0" src="ball16.gif" width="29" height="28" alt="Ball">
</body>
</html>                                                                                                                                                                       




Event Object: Which event type occurred?


<html>
<head>


<script type="text/javascript">
function whichType(event) {
alert(event.type)
}
</script>
</head>


<body onmousedown="whichType(event)">


<p>
Click on the document. An alert box will alert which type of event occurred.
</p>


</body>
                   </html>




    SEE VIDEO




0 Responses So Far:

Related Post

 
Back To Top