问题
I have implemented this javascript with a hard coded date and it is displaying properly, I have tried it in a griview but it is rather showing the enddate from my database without showing the countdown, but i want to be getting the enddate from the database: Also, when the countdown is over it should display a message: "Project over" Please friends help me out.
<script type="text/javascript" src="../Scripts/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="../Scripts/jquery.countdown.min.js"></script>
<script type="text/javascript" src="../Scripts/jquery.countdown.js"></script>
<asp:TemplateField HeaderText="CountDown" ItemStyle-Width="300px">
<ItemTemplate>
<div id="myCountdownClass"><%# !string.IsNullOrEmpty(Eval("EndDate").ToString()) ? Convert.ToDateTime(Eval("EndDate")).ToString("MM'/'dd'/'yyyy") : "" %></div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<script type="text/javascript">
$(document).ready(function () {
$('.myCountdownClass').each(function () {
var date = $(this).text();
$(this).countdown(date, function (event) {
$(this).text(event.strftime('%D days %H:%M:%S'));
});
});
});
</script>
回答1:
You specified id
in your template, but you're trying to select a class in your javascript ($('.myCountdownClass')
). Change this:
<div id="myCountdownClass">
to this:
<div class="myCountdownClass">
Here's the working example (check script.js
file):
http://embed.plnkr.co/uffoqIjhqvvV7lzFlmzu/
来源:https://stackoverflow.com/questions/45881223/javascript-countdown-timer-not-showing-in-gridview