M
Mattia Campagna
Ospite
Codice:
<html> <head>
<title>Snake</title>
<style type="text/css">
#campo {
width: 500px;
height: 500px;
background-color: white;
border: thin solid black;
}
.cella {
width: 10px;
height: 10px;
float: left;
}
</style>
<script type="text/javascript">
// riempio il campo di celle vuote
function inizia() {
for(var i=0; i<2500; i++)
creaCella();
}
// crea nuova cella vuota
function creaCella() {
var cella = document.createElement("div");
cella.setAttribute("class", "cella");
var img = document.createElement("img"); // creo attributo immagine
img.setAttribute("src", "vuota.png");
cella.appendChild(img);
document.getElementById("campo").appendChild(cella);
}
</script>
</head>
<body onload="inizia()">
<div id="campo"> <!-- riempio di case con js --> </div>
</body>
</html>
Questo codice in Chrome mi riempie correttamente il div "campo" con 2500 div.
In Explorer non vuol sentire di funzionare e visto che devo ottimizzare lo script per explorer e firefox credo di noon essere sulla buona strada.
Consigli?