1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="fr">
<!-- Do not care about the following head and styles, this is
-- just there to get a nice and usable sample.
-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Test</title>
<style type="text/css">
a, span, img { display:block; }
a { margin-bottom:1.5em; text-align:center; width:50px; }
span { font-size:75%; }
img { width:50px; }
</style>
</head>
<body>
<p>
Cliquez sur le bouton 1 et 2 pour comparer le paramètre
indiquant l'objet recevant l'événement.
</p>
<!-- Start of button -->
<a href="#" id="button1">
<span>
<img src="no-picture1.gif">
</span>
<span>Bouton 1</span>
</a>
<!-- End of button -->
<!-- Start of button -->
<a href="#" id="button2">
<span>
<img src="no-picture2.gif">
</span>
<span>Bouton 2</span>
</a>
<!-- End of button -->
</body>
<script language="JavaScript">
// Handler of button 1 : via assignment of a property
var button1;
button1 = document.getElementById("button1");
button1.onmousedown = onButtonDown1;
function onButtonDown1 ()
{
var element = event.srcElement;
alert('Bouton 1 this: ' + this.tagName);
alert('Bouton 1 element: ' + element.tagName);
}
// Handler of button 2 : via attachEvent
var button2;
button2 = document.getElementById("button2");
button2.attachEvent('onmousedown', onButtonDown2);
function onButtonDown2 ()
{
var element = event.srcElement;
alert('Bouton 2 this: ' + this.tagName);
alert('Bouton 2 element: ' + element.tagName);
}
</script>
</html> |
Partager