jquery实现倒计时和当前时间的显示

来源:互联网 发布:淘宝朋友代付退款到哪 编辑:程序博客网 时间:2024/06/05 02:39

js代码

<script type="text/javascript"            src="${pageContext.request.contextPath}/js/jquery-1.4.3.js">            </script><script type="text/javascript">    var second = 4;    var timer ;    $(function() {        $('#time').html(currentTime);        timer = window.setInterval(function(){            if (second <= 0) {                location.href = "${pageContext.request.contextPath}";            } else {                $("#totalSecond").html(second--);            }        }, 1000);        var displayTime = window.setInterval(function(){         $('#time').html(currentTime)        },1000);    });    function cancel(){        window.clearInterval(timer);    }    function currentTime(){        var d = new Date(),str = '';         str += d.getFullYear()+'年';         str  += d.getMonth() + 1+'月';         str  += d.getDate()+'日';         str += d.getHours()+'时';         str  += d.getMinutes()+'分';        str+= d.getSeconds()+'秒';        return str;        }     </script>


jsp页面

<span style="color: green"><span id="totalSecond">5</span>                        秒后自动跳转至当当商城</span>                    <a href="javascript:;" onclick="cancel();" style="color: red">取消</a> <span style="color:green">当前时间<span id="time"></span></span>