1

这是完整的代码:

  <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
    <style type="text/css">
        @import "jquery.countdown.css";
    </style>
    <script type="text/javascript" src="Scripts/jquery.countdown.js"></script>
    <script type="text/javascript">
        $('#shortly').countdown({ until: shortly,
            onExpiry: liftOff, layout: "{ps} seconds to go"
        });

        $(document).ready(function () {
            shortly = new Date();
            shortly.setSeconds(shortly.getSeconds() + 5.5);
            $('#shortly').countdown('change', { until: shortly });
        });

        function liftOff() {
            // refresh the page  
            window.location = window.location;
        }   

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <span id="shortly"></span>
    </form>
</body>
</html>

我在 Visual Studio 的 Scriptsmap 中有 jquery.countdown.js。样式表“jquery.countdown.css”也在项目中。

不知道问题可能是什么。我对 jquery 很陌生,并试图学习它。

4

2 回答 2

1

我不熟悉这个倒计时插件,但是,尝试移动部分

    $('#shortly').countdown({ until: shortly,
        onExpiry: liftOff, layout: "{ps} seconds to go"
    });

进入传递给的函数$(document).ready,替换$('#shortly').countdown('change', { until: shortly });

因为否则,shortly当您尝试使用 var 时,它不会被初始化。

于 2010-05-19T13:13:53.770 回答
0

你在 liftOff 函数中有一个错误windowwindow.location

function liftOff() {
    // refresh the page  
    window.location = window.location;
} 
于 2010-05-19T11:53:02.373 回答