Javascript 使用AJAX的Jquery脚本,不使用';I don’我不能一直工作
我有以下Jquery脚本,它计算两个日期之间的天数,并根据剩余时间更改单元格的颜色 现在,计算是有效的,但它不总是有效的是,当我打开第一次打开它时,大多数时候显示此信息的选项卡时,它是有效的,但如果我再次单击它或单击另一个选项卡,它将不会显示颜色的变化Javascript 使用AJAX的Jquery脚本,不使用';I don’我不能一直工作,javascript,jquery,ajax,Javascript,Jquery,Ajax,我有以下Jquery脚本,它计算两个日期之间的天数,并根据剩余时间更改单元格的颜色 现在,计算是有效的,但它不总是有效的是,当我打开第一次打开它时,大多数时候显示此信息的选项卡时,它是有效的,但如果我再次单击它或单击另一个选项卡,它将不会显示颜色的变化 <script> function expiryDates() { var warning = "<?php echo config('WARNING_DATE')?>"; va
<script>
function expiryDates() {
var warning = "<?php echo config('WARNING_DATE')?>";
var critical = "<?php echo config('CRITICAL_DATE')?>";
//gets and creates array of all TD 'lod' dates
var expDate = "<?php echo $content['lod'] ?>";
//var value = $(this).text();
expDate = expDate.split("-");
//Gets today's date and formats it to MYSQL date format
var now = (new Date()).toISOString().substring(0, 10);
now = now.split("-");
//Converts all TD dates into days
var eDate = new Date(expDate[0] + "-" + expDate[1] + "-" + expDate[2]);
//Converts today's date into day
var sDate = new Date(now[0] + "-" + now[1] + "-" + now[2]);
//Does the math
var daysApart = Math.abs(Math.round((sDate - eDate) / 86400000));
//Changes cells color
if (daysApart < critical) {
//$("#expiration-date").addClass('expired');
$("#expiration-date").css("color", "red");
} else if ((daysApart > critical) && (daysApart <= warning)) {
$("#expiration-date").css("color", "#orange");
// $("#expiration-date").addClass('about_expired');
} else if (eDate < sDate) {
$("#expiration-date").css("color", "red");
// $("#expiration-date").addClass('expired');
}
}
</script>
及
但结果是一样的
如有任何意见,将不胜感激
谢谢大家!
编辑:
很抱歉丢失了信息 设置的方式是,我有一个主刀片,它调用此信息选项卡: 主刀片具有以下代码:
<td class="detail-slide-specifications" id="detail-slide-specifications{{ $item['mainHwID'] }}" onclick="showSpecifications({{ $item['mainHwID'] }})">
发布调用函数的Ajax代码Ajax调用的async属性如何?尝试制作一个复制您的问题的小提琴。这里没有Ajax调用。不知道您的页面是否有id='expiration-date'的元素。我不知道PHP填充了哪些值,也许您可以在页面上查看不工作时的源代码,并查看var warning、critical和expDate包含的内容。对于丢失的信息,非常抱歉。我刚把它添加到我的帖子里。
$( window ).on( "load", expiryDates);
<td class="detail-slide-specifications" id="detail-slide-specifications{{ $item['mainHwID'] }}" onclick="showSpecifications({{ $item['mainHwID'] }})">
function showSpecifications(masterID)
{
var itemID = "#detail-panel-specs" + masterID ;
var loadingImgClass = ".specifications_loading_spinner_" + masterID ;
if (masterID == "") {
$(itemID).html( "Error : No Master ID");
return;
} else {
var request = $.ajax({
url: "get_specifications?masterID=" + masterID,
type: "get",
timeout: 5000
});
request.done(function (responseText) {
$(loadingImgClass).hide();
$(itemID).html(responseText);
});
request.fail(function (jqXHR, textStatus, errorThrown) {
$(loadingImgClass).hide();
$(itemID).html("Error " + errorThrown);
});
}
}