Hvordan laver jeg dette script om?
Jeg fandt dette script et eller andet sted. men jeg vil gerne være fri for at skulle skrive 3 linjer for hver billede.if (document.images) {
button1___up = new Image(36,32); button1___up.src = "button1___up.gif";
button1_init = new Image(36,32); button1_init.src = "button1_init.gif";
button1_down = new Image(36,32); button1_down.src = "button1_down.gif";
button2___up = new Image(36,32); button2___up.src = "button2___up.gif";
button2_init = new Image(36,32); button2_init.src = "button2_init.gif";
button2_down = new Image(36,32); button2_down.src = "button2_down.gif";
}
Til et script der generer de 3 tre linjer for hver plads der er i et array?
jeg har forsygt med.
if (document.images)
{
var a = 2; // a == number of buttons
ButtonArray = new Array(a) ;
ButtonArray[0] = "Home" ;
ButtonArray[1] = "About" ;
// osv.
var ArLength = ButtonArray.length ;
for( i = 0 ; i < ArLength ; i++)
{
var (Button_ + i) = eval(ButtonArray[i] + "_Over");
eval(ButtonArray[i] + "_Over") = new Image(100,14); eval(ButtonArray[i] + "_Over.src") = eval(ButtonArray[i] + "ON.gif");
eval(ButtonArray[i] + "_Out") = new Image(100,14); eval(ButtonArray[i] + "_Out.src") = eval(ButtonArray[i] + "OFF.gif");
eval(ButtonArray[i] + "_Click") = new Image(100,14); eval(ButtonArray[i] + "_Click.src") = eval(ButtonArray[i] + "ON.gif");
}
}