Sorry, men jeg er virkelig på gyngende grund når vi taler
Javascript :(
Jeg forsøger mig med et lille counter script (se nedenfor).
Firefox kører det fint men IE fejler med en meddelelse der siger:
"cNaN" er ikke defineret
Er der mon nogen der kan se hvor fejlen opstår?
Scriptet:
<SCRIPT LANGUAGE="JavaScript">
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!!
http://javascript.internet.com -->
<!-- Begin
//Created by DendE PhisH
function getTime() {
c1 = new Image(); c1.src = "/Includes/CountDown/1c.gif";
c2 = new Image(); c2.src = "/Includes/CountDown/2c.gif";
c3 = new Image(); c3.src = "/Includes/CountDown/3c.gif";
c4 = new Image(); c4.src = "/Includes/CountDown/4c.gif";
c5 = new Image(); c5.src = "/Includes/CountDown/5c.gif";
c6 = new Image(); c6.src = "/Includes/CountDown/6c.gif";
c7 = new Image(); c7.src = "/Includes/CountDown/7c.gif";
c8 = new Image(); c8.src = "/Includes/CountDown/8c.gif";
c9 = new Image(); c9.src = "/Includes/CountDown/9c.gif";
c0 = new Image(); c0.src = "/Includes/CountDown/0c.gif";
Cc = new Image(); Cc.src = "/Includes/CountDown/Cc.gif";
now = new Date();
//ENTER BELOW THE DATE YOU WISH TO COUNTDOWN TO
later = new Date("<%= "" & Counter & ""%>");
days = (later - now) / 1000 / 60 / 60 / 24;
daysRound = Math.floor(days);
hours = (later - now) / 1000 / 60 / 60 - (24 * daysRound);
hoursRound = Math.floor(hours);
minutes = (later - now) / 1000 /60 - (24 * 60 * daysRound) - (60
* hoursRound);
minutesRound = Math.floor(minutes);
seconds = (later - now) / 1000 - (24 * 60 * 60 * daysRound) - (60
* 60 * hoursRound) - (60 * minutesRound);
secondsRound = Math.round(seconds);
if (secondsRound <= 9) {
document.images.g.src = c0.src;
document.images.h.src = eval("c"+secondsRound+".src");
}
else {
document.images.g.src =
eval("c"+Math.floor(secondsRound/10)+".src");
document.images.h.src = eval("c"+(secondsRound%10)+".src");
}
if (minutesRound <= 9) {
document.images.d.src = c0.src;
document.images.e.src = eval("c"+minutesRound+".src");
}
else {
document.images.d.src =
eval("c"+Math.floor(minutesRound/10)+".src");
document.images.e.src = eval("c"+(minutesRound%10)+".src");
}
if (hoursRound <= 9) {
document.images.y.src = c0.src;
document.images.z.src = eval("c"+hoursRound+".src");
}
else {
document.images.y.src =
eval("c"+Math.floor(hoursRound/10)+".src");
document.images.z.src = eval("c"+(hoursRound%10)+".src");
}
if (daysRound <= 9) {
document.images.x.src = c0.src;
document.images.a.src = c0.src;
document.images.b.src = eval("c"+daysRound+".src");
}
if (daysRound <= 99) {
document.images.x.src = c0.src;
document.images.a.src =
eval("c"+Math.floor((daysRound/10)%10)+".src");
document.images.b.src =
eval("c"+Math.floor(daysRound%10)+".src");
}
if (daysRound <= 999){
document.images.x.src =
eval("c"+Math.floor(daysRound/100)+".src");
document.images.a.src =
eval("c"+Math.floor((daysRound/10)%10)+".src");
document.images.b.src =
eval("c"+Math.floor(daysRound%10)+".src");
}
newtime = window.setTimeout("getTime();", 1000);
}
// End -->
</script>
--
Vil du lære at kode HTML, XHTML, CSS, SSI, ASP eller ASP.NET?
- Pædagogiske tutorials på dansk
- Kom godt i gang med koderne
KLIK HER! =>
http://www.html.dk/tutorials