当前日期和时间的javascript不显示

时间:2018-11-21 16:30:37

标签: javascript jquery html

我有以下代码,我试图插入当前日期和tome,但似乎无济于事。请帮忙。我想将其插入“护照设施等待时间”的下面。我添加了功能和多项功能,但有时它什么也不显示或什么都不做

<!DOCTYPE html>
<html>
<head>
    <title>IWT</title>
    <meta charset="utf-8" />
    <meta http-equiv="x-ua-compatible" content="IE=11">
    <link href="css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
    <!--<button>Refresh Stats</button> -->
    <div class="container">
        <h2><center>Passports Facility Waiting Time</center></h2>
    <div id="iwtDisplay" class="table" table align="center">
        <div id="servicesDiv">
        </div>            
    </div>
    <script src="js/jquery-3.3.1.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script>
        /* Request IWTWeb URL via AJAX call through jQuery */ 
        /*
        Author: S. Rogers
        Date: 10-16-2018
        Description: Basic HTML template using jQuery to display IWT results with auto-refresh for use with Coral Gables xml_IWT_Stats.aspx (IWT 4.0)
        */
        // local vars
        var services;
        var xmlTest;
        var time;
        var timeformatted;
        $(document).ready(function () {
            $.ajax({
                type: "GET",
                url: "http://iwtweb.coral......,
                dataType: "xml",
                success: xmlParser // on success, parse the XML data as defined below
            });

            // auto-refresh get results every 3 seconds (3000 ms)
           setInterval(function () {
                $.ajax({
                    type: "GET",
                    url: "http://iwtweb.coral.....",
                    dataType: "xml",
                    success: xmlParser // on success, parse the XML data as defined below
                });
            }, 3000);   
            function xmlParser(xml) {
                // find the <Unit> node and retrieve the attribute UnitName
                var unitName = $(xml).find('UnitName')[0].innerHTML;
                var numActiveWindows = $(xml).find('NumActiveWindows')[0].innerHTML;

                var serviceStats = ['', '', ''];

                xmlTest = $(xml).find('Unit');
                services = $(xml).find('Service');
                $('#servicesDiv').html('<thead class="thead-light"><tr><th>Current Waiting Time</th><th>Avg Waiting Time</th><th>Number of Customers Waiting<th><th>Number of Windows</th></tr></thead>');

                serviceStats[0] = $(xml).find('Service')[0].childNodes[0].innerHTML;
                serviceStats[1] = $(xml).find('Service')[0].childNodes[1].innerHTML;
                serviceStats[2] = $(xml).find('Service')[0].childNodes[2].innerHTML;
                $('#servicesDiv').append('<tbody id="service0"></body>');
                // create divs with current values of childNodes of <Service>
                serviceHtml = '<tr><td>' + secondsToTime(serviceStats[0]) + '</td><td>' + secondsToTime(serviceStats[1]) + '</td><td>' + serviceStats[2] + '</td><td>' + '</td><td>' + numActiveWindows + '</td></tr>';

                // append the #service0 div with the new HTML
                $('#service0').append(serviceHtml);

                // update the #unitDiv with the unitName value from the XML
                $("#unitDiv").html(unitName);
            }

        // format seconds to timespan
        function secondsToTime(secs)
        {
                secs = Math.round(secs);
                var hours = Math.floor(secs / (60 * 60));

                var divisor_for_minutes = secs % (60 * 60);
                var minutes = Math.floor(divisor_for_minutes / 60);

                var divisor_for_seconds = divisor_for_minutes % 60;
                var seconds = Math.ceil(divisor_for_seconds);

                return hours + ':' + minutes + ' Minutes';

                //var hoursText;
                //var minutesText;
                //var secondsText;

                // leading zeros
                //if  (hours<10)
                    //hoursText = '0' + hours.toString();
                //else
                    //hoursText = hours.toString();

                //if (minutes < 10)
                    //minutesText = '0' + minutes.toString();
                //else
                    //minutesText = minutes.toString();

                //if (seconds < 10)
                    //secondsText = '0' + seconds.toString();
                //else
                    //secondsText = seconds.toString();

                //return hoursText + ':' + minutesText + ':' + secondsText;
        }         
        });
    </script>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

您可以包括一个脚本,该脚本将当前日期和时间设置为低于Passports设备的等待时间。您可以看到此fiddle。112-117行正在设置日期时间。这些行在下面提到

 <script>
    (()=> {
let el = document.querySelector("time");
el.innerHTML = new Date()
})()
    </script>