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
| <html>
<head>
<title>test javascript</title>
<script language="javascript">
function assignFct()
{
eachDiv = document.body.getElementsByTagName("div");
for (i = 0; i < eachDiv.length; i++)
{
if (eachDiv[i].addEventListener) //firefox
eachDiv[i].addEventListener('click', function(){alert(i)}, false);
else if (eachDiv[i].attachEvent) //IE
eachDiv[i].attachEvent('onclick', function(){alert(i)});
}
}
</script>
</head>
<body>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<span onclick="assignFct();">test</span>
</body>
</html> |