<?xml version="1.0" encoding="iso-8859-15" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JavaScript Functionsreferenz bei onclick funktioniert nicht</title>
<style type="text/css">
div.box
{
display: block;
}
div.box_invis
{
display: none;
}
</style>
<script type="text/javascript">
function start()
{
for (var i = 0; i < 3; i++)
{
var box = document.getElementById("box");
var a = document.createElement("a");
a.href = "#box_" + i;
a.onclick = function () { showbox(i); };
a.appendChild(document.createTextNode("showbox(" + i + ")"));
box.appendChild(a);
}
}
function showbox(nr)
{
var box = document.getElementById("box_" + nr);
box.className = "box";
}
</script>
</head>
<body onload="start()">
<div class="box" id="box" />
<div class="box_invis" id="box_0">0</div>
<div class="box_invis" id="box_1">3</div>
<div class="box_invis" id="box_2">2</div>
</body>
</html>
Kann mir bitte irgendjemand sagen warum das nicht funktioniert?
Das JavaScript soll einfach nur beim Klick auf einen der generierten Links die Funktion (showbox) ausführen, welche die Klasse eines <div>'s ändert.
--
ie:% fl:| br:^ va:} ls:& fo:| rl:( n4:( ss:| de:] js:| ch:? sh:( mo:| zu:)
ie:% fl:| br:^ va:} ls:& fo:| rl:( n4:( ss:| de:] js:| ch:? sh:( mo:| zu:)