简体   繁体   中英

Compare date with if statement in jQuery to do list

I want to highlight overdue task when refresh page and when click on add task button such as the code below:

$(document).ready(function(){
  $('.add-task').on('click',function(){
    $('.task-date').each(function(){
      var a = new Date().dateFormat('dd/mm/yy').getTime();
      var b = formatDate(b,'dd/mm/yy').getTime();
      var task = new Date($('.task-date')).getTime();
      if(task < b) {
        return $('todo-task').addClass('overdue');
      }
    });
  });
});

I tried some other ways but still not working so please check JSFiddle here and source site here and help me. Thank you.

    var generateElement = function(params){
        var parent = $(codes[params.code]),
            wrapper;

        if (!parent) {
            return;
        }
        var curDate=new Date();
        var overDueClass="";
        if(params.date<curDate){ //  Check the current date is less than to-do date here
           overDueClass=" overdue";
        }
        wrapper = $("<div />", {
            "class" : defaults.todoTask+overDueClass,
            "id" : defaults.taskId + params.id,
            "data" : params.id
        }).appendTo(parent);
      .....................
      ...............
}

For solve your task no need to create new functions. You may just apply the logic in generateElement function in your todo.js file.

    var d = new Date();
    var date = d.getDate() + "/" + d.getMonth()+1 + "/" + d.getFullYear();
    var overDueClass= "";
    // Add Task
    var generateElement = function(params){
    var parent = $(codes[params.code]),
        wrapper;

    if (!parent) {
        return;
    }
    //  Check the current date is less than to-do date.
    if(params.date < date) {
    overDueClass= "overdue";
  } else {
    overDueClass="";
  };

    wrapper = $("<div />", {
        "class" : defaults.todoTask+" "+overDueClass,
        "id" : defaults.taskId + params.id,
        "data" : params.id
    }).appendTo(parent);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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