为什么我的这个jquery代码出现NaN错误?

时间:2019-11-30 07:48:37

标签: javascript jquery cordova

我正在尝试计算从数据库获得的每个数据的时差,但显示的是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>');

    });

1 个答案:

答案 0 :(得分:1)

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

您在创建新的Date时将字符串与jQuery对象串联。