Jquery学习2---倒计时

以下代码是mvc4.0代码,其功能是让页面上的数字3,变2,变1 然后跳转页面

 

 

 

@{

    ViewBag.Title = "LoginOut";

}

<html>

<head>

<title></title>

<script src="../../Content/Jquery.js" type="text/javascript"></script>

<script type="text/javascript" language="javascript">

var _a = false;//<!--这个必须有-->

    $(function () {

     if (!_a) {//<!--这个必须有-->

        change();

        setTimeout(function () {

            window.location.href ="@Url.Content("~/Home/Index")";

        }, 3000);

        }

    })

    function change() {

        var i = parseFloat(document.getElementById("span").innerHTML);

        setTimeout(function () {

            if (i > 0) {

                document.getElementById("span").innerHTML = (i - 1).toString();

                change();

            }

        }, 1000);

    }

     function clickself() {

            if (window != top) {

                top.location.href = "@Url.Content("~/Home/Index")";

 

            } else {

                window.location.href = "@Url.Content("~/Home/Index")";

            }

        }

</script>

</head>

<body>

<div>

<h2 id="msg">登陆已超时,请重新登录!</h2>

<p id="p_time">

正在为您跳转:

<span id="span"  style=" color:Green">3</span>秒<br />

如不能正常跳转请直接点击:<a href="#" onclick="clickself()">进入登录页面</a>

</p>

</div>

</body>

</html>

posted @ 2013-11-18 19:02  JIN__JIN  阅读(121)  评论(0编辑  收藏  举报