首先:引入jquery文件
<script type="text/javascript" src="http://www.cnblogs.com/Content/Phone/js/Answer.js?201402242021"></script>
然后写javascript代码
<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>