简体   繁体   English

为什么我收到此 jquery 代码的 NaN 错误?

[英]Why am i getting NaN error for this jquery code?

I'm trying to calculate time difference for each of the data gotten from database but it displays NaN Instead of the time difference我正在尝试计算从数据库中获取的每个数据的时差,但它显示 NaN 而不是时差

$(document).ajaxError(function(event, request, settings) {
    $('#busy').hide();
    alert("Error accessing the server");
});

function getEmployeeList() {
    $('#busy').show();
    $.getJSON(serviceURL + 'getemployees.php', function(data) {
        $('#busy').hide();
         $('#employeeList li').remove();
        employees = data.items;
        $.each(employees, function(index, employee) {
            var valuestart = $("00:00:00");
            var valuestop = $("05:00:00");

            var timeStart = new Date("01/01/2007 " + valuestart).getHours();
            var timeEnd = new Date("01/01/2007 " + valuestop).getHours();

            var difference = timeEnd - timeStart;
        $('#employeeList').append('<li><a href="employeedetails.html?id=' + employee.id + '">' +
                '<img src="js/citybus.png" class="list-icon"/>' +
                '<p class="line1">' + employee.firstName + '</p>' +
                '<p class="line2">' + difference + '</p>' +
                '<span class="bubble">' + employee.managerId + '</span></a></li>');

    });
var valuestart = "00:00:00";
var valuestop = "05:00:00";

You're concatenating a string with an jQuery object when creating a new Date.创建新日期时,您将字符串与 jQuery 对象连接起来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM