我正在尝试使用C#Web应用程序中的jQuery进行多次倒计时。
我的数据库中有两个不同的日期,我将其插入到javascript中。这样可以正常工作,但是javascript使用了与DB相同的日期,并且它很可能因为jres只有一个实例,所以我需要一些如何解决这个问题的建议。
这是完整的代码。
标记:
<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>";
}
提前致谢:)