根据日期在jQuery中将div添加到div

时间:2017-06-23 16:31:47

标签: javascript jquery datatables

我承认JavaScript不是那么棒。

我的任务是建立一个实用程序来检查一个广告系列日期是否会在2周或更短的时间内过期,并添加一个类,如果它要去。

日期来自服务,它的构建(数据表图)如下 数据未定义,但这是一个不同的问题。

任何反馈都会非常感激,因为我似乎没有任何运气。

最初我有一个日期对象,但不确定是否有必要。

/*HTML Rendered Out for that table cell (there are multiple but this is how it 
comes out*/
 <td class=" campaign_start_date small-screen small-screen-2-col">06/14/2017 - 
 <div class="campaign-end-date">06/29/2017</div></td>

enter image description here      JS     //数据表代码&amp;为我们的项目修改

{title:ax.L(114), class:'campaign_start_date small-screen small-screen-2-col', data:function(row, type, val, meta) {

  var campaignEndDate = ax.Utils.deNull(row.campaign_end_date, '');
  campaignEndDate = ax.Utils.RFCFormat(campaignEndDate, { excludeTime: true });
  var campaignStartDate = ax.Utils.deNull(row.campaign_start_date, '');
  campaignStartDate = ax.Utils.RFCFormat(campaignStartDate, { excludeTime: true });
  var campaignDateString;

  if (campaignEndDate && campaignStartDate ) {
    campaignDateString = campaignStartDate  + ' - ' + '<div class="campaign-end-date">' + ax.Utils.campaignEndDateAlert(campaignEndDate)  + '</div>';      
  } else {
    if (!campaignEndDate && campaignStartDate) {
      campaignDateString = campaignStartDate +  ' - ? ';
    } 

    else if (!campaignStartDate && campaignEndDate) { 
      campaignDateString = ' ? - ' +  campaignEndDate;
    }
    else {
      campaignDateString = ' ';
    }
  }
  return campaignDateString

  //My attempt at doing this from the Utility file - the code that i'm having no luck with.

  publicMethods.campaignEndDateAlert = function (data) {
    var campaignDateEnd = data.campaign_end_date;
    var $orderTable = $('#order-table');
    var $campaignDate = $orderTable.find('.campaign-end-date')

    if (campaignDateEnd <= campaignDateEnd + 86400000) {
      $campaignDate.addClass('green');
    }
  }

0 个答案:

没有答案