有趣的JavaScript小程序

 1 <!doctype html>

 2 <html lang="en">

 3  <head>

 4   <meta charset="UTF-8">

 5   <meta name="Generator" content="EditPlus®">

 6   <meta name="Author" content="">

 7   <meta name="Keywords" content="">

 8   <meta name="Description" content="">

 9   <title>倒计时</title>

10  </head>

11 

12 <script type="text/javascript">

13 <!--

14     h= 0

15     m= 0

16     s= 30

17     

18     function cal()

19     {

20          --s

21           if (s < 0)

22           {

23               --m

24               s= 59

25            }

26           if (m < 0)

27           {

28               --h

29               m= 59

30           }

31         if(h>=0)    document.aa.t1.value= h+": "+m+": "+s

32         else    {

33             alert("考试结束,恭喜你撑到了最后!")

34             num= 8

35             s= "Do you want to anymore? \n    "

36             hehe= "0.0 "

37             haha= "~.~ "

38             for(i=1; i<=num; ++i) {

39                 str= s

40                 for(j=1; j<=i; ++j)        str= str+ ( Math.random( )< 0.5 ? hehe: haha )

41                 alert ( str )

42             }

43             return

44         }

45         setTimeout("cal()",200)

46     }

47 //-->

48 </script>

49 

50  <body bgcolor= #33ffff>

51         <form name="aa">

52             距离考试结束还剩下:

53             <input type=text name="t1">

54         </form>

55         <SCRIPT LANGUAGE="JavaScript">

56             <!--

57             cal()

58             //-->

59         </SCRIPT>

60  </body>

61 </html>

你可能感兴趣的:(JavaScript)