with promot, u get a string

来源: 2003-11-27 11:05:00 [旧帖] [给我悄悄话] 本文已被阅读:

you can use parseInt() to get the integer.
BTW, it is javascript, not java in html. Although they look alike, they are totally different.
the following is a code for reference


var in_days,in_hours,in_minutes,in_seconds,in_total_seconds;

do{//if it is not a number,ask user to enter again. you can remove this loop if you don't need to validate user input
in_days=parseInt(prompt("Please enter a number of days:" ));
}while(isNaN(in_days));

do{
in_hours=parseInt(prompt("Please enter a number of hours:" ));
}while(isNaN(in_hours));

do{
in_minutes=parseInt(prompt("Please enter a number minutes: "));
}while(isNaN(in_minutes));

do{
in_seconds=parseInt(prompt("Please enter a number seconds: "));
}while(isNaN(in_seconds));

do{
in_total_seconds=in_seconds+in_minutes*60+in_hours*60*60+in_days*24*60*60;
}while(isNaN(in_total_seconds));

alert(in_total_seconds);





--文学城www.wenxuecity.com--