1

私はjqueryを書いていますが、730日を超える場合は色を変更する必要があります..730日から183日の間...など。if else ステートメントに何か問題がある場合、私のページでうまく機能しませんか? ここにすべての jquery がありますが、if/else 部分のヘルプが必要です。

$(document).ready(function () {
'use strict';

var monthNames = [ "January", "February", "March", "April", "May", "June",
        "July", "August", "September", "October", "November", "December" ],

    dayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],

    newDate = new Date();

$('#safetyRecord').hide();

$('#today').text(dayNames[newDate.getDay()] + "," + ' ' + monthNames[newDate.getMonth()] + ' ' + newDate.getDate() + "," + ' ' + newDate.getFullYear());

$('#checkRecord').click(function () {

    var dateOfLastAccident = new Date($('#dateOfLastAccident').val());

    var today = new Date(),

        daysSinceLastAccident = Math.floor((today.getTime() - dateOfLastAccident.getTime()) / (25 * 60 * 60 * 1000));

    $('#daysSinceLastAccident').text(daysSinceLastAccident);

    $('#safetyRecord').show();

if (daysSinceLastAccident >= parseInt(730)){
    {
    $('#safetyRecord').addClass('great');
    }

else if (daysSinceLastAccident >=730<=183)
{
    $('#safetyRecord').addClass('good');
}

else if (daysSinceLastAccident >=183<=60) 
{
    $('#safetyRecord').addClass('.marginal');
}
else if (daysSinceLastAccident >=60<= 14) 
{
    $('#safetyRecord').addClass('.poor');
}
else (daysSinceLastAccident < 14)
{
    $('#safetyRecord').addClass('.disaster');
}


});

});

4

3 に答える 3