0

我正在尝试在 C# Web 应用程序中使用 jQuery 进行多个倒计时。

我的数据库中有两个不同的日期,我将它们插入到 javascript 中。这很好用,但是 javascript 使用数据库中的相同日期,这可能是因为只有一个 javascript 实例,所以我需要一些关于如何解决这个问题的建议。

这是完整的代码。

标记:

<script type="text/javascript" src="scripts/jquery.countdown.js"></script>
<script type="text/javascript">
    $(function () {
        var count = new Date('<%=Datestring%>');
        var countdown = setInterval(function () {
            $('.countdown').countdown({ until: count, format: 'DHMS' });
            if (count == 0) {
                window.location = 'http://google.com';
            }
            count--;
        }, 1000);
    });
</script>

<asp:Repeater ID="repAuctions" runat="server" OnItemDataBound="repAuctions_OnItemDataBound">
    <ItemTemplate>
        <div>
            <asp:Literal ID="litHeading" runat="server" />
            <br/>
            <asp:Literal ID="litCountDown" runat="server" />
        </div>
    </ItemTemplate>
</asp:Repeater>

后端:

public string Datestring;
    protected void Page_Load(object sender, EventArgs e)
    {
        repAuctions.DataSource = AuctionsFactory.GetAllAuctions();
        repAuctions.DataBind();
    }

    protected void repAuctions_OnItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        var auction = (Auction)e.Item.DataItem;
        var litCountDown = (Literal)e.Item.FindControl("litCountDown");
        var litHeading = (Literal)e.Item.FindControl("litHeading");

        string format = "ddd MMM d yyyy HH:mm:ss";
        var countdowndate = (DateTime) auction.TimeLeft;
        Datestring = countdowndate.ToString(format);

        litHeading.Text = auction.Heading;
        litCountDown.Text = auction.TimeLeft + "<span class='countdown'></span>";
    }

提前致谢 :)

4

0 回答 0