首先:引入jquery文件
1
|
<script type= "text/javascript"
src= "http://www.cnblogs.com/Content/Phone/js/Answer.js?201402242021" ></script>
|
然后写javascript代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
<script type= "text/javascript" >
$(function () {
timer;
})
var
maxtime = 20 * 100;
function CountDown() {
if
(maxtime >= 0) {
seconds = Math.floor(maxtime / 100);
milliseconds = Math.floor(maxtime % 100);
seconds = seconds < 10 ? ( "0"
+ seconds) : seconds;
milliseconds = milliseconds < 10 ? ( "0"
+ milliseconds) : milliseconds;
$( ".time" ).text(seconds + ":"
+ milliseconds);
//if(maxtime == 5*60) alert(‘注意,还有5分钟!‘);
if
(maxtime == 270) {
//$("#musicNear")[0].play();
}
maxtime -= 10;
}
}
timer = window.setInterval(CountDown, 100);
</script> |