javascript gridview 中没有显示倒数计时器
javascript countdown timer not showing in gridview
我已经用硬编码日期实现了这个 javascript 并且它显示正确,我已经在 griview 中尝试过但它只是显示我的数据库的结束日期而不显示倒计时,但我想要从数据库中获取结束日期:此外,当倒计时结束时,它应该显示一条消息:"Project over"请朋友帮帮我。
<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>
您在模板中指定了 id
,但您试图在 javascript ($('.myCountdownClass')
) 中 select class。改变这个:
<div id="myCountdownClass">
对此:
<div class="myCountdownClass">
这是工作示例(检查 script.js
文件):
我已经用硬编码日期实现了这个 javascript 并且它显示正确,我已经在 griview 中尝试过但它只是显示我的数据库的结束日期而不显示倒计时,但我想要从数据库中获取结束日期:此外,当倒计时结束时,它应该显示一条消息:"Project over"请朋友帮帮我。
<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>
您在模板中指定了 id
,但您试图在 javascript ($('.myCountdownClass')
) 中 select class。改变这个:
<div id="myCountdownClass">
对此:
<div class="myCountdownClass">
这是工作示例(检查 script.js
文件):