javascript countdown timer not showing in gridview

旧巷老猫 提交于 2019-12-13 03:15:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!