在此点击处理程序代码中:
$('#save').click(function () {
if (overAllStatus == 'red') {
rows[lastRowClicked].cells[0].innerHTML = '<a class="modalInput" rel="#flagsSummary" style="cursor:pointer"><img src="/FatcaOne_0/static/images/circleRed.png" width="20" height="20"></a>';
}
else if (overAllStatus == "yellow") {
rows[lastRowClicked].cells[0].innerHTML = '<a class="modalInput" rel="#flagsSummary" style="cursor:pointer"><img src="/FatcaOne_0/static/images/circleYellow.png" width="20" height="20"></a>';
console.log('Over all status is yellow.');
}
else if (overAllStatus == 'greenR') {
rows[lastRowClicked].cells[0].innerHTML = '<a class="modalInput" rel="#flagsSummary" style="cursor:pointer"><img src="/FatcaOne_0/static/images/circleGreenHollow.png" width="20" height="20"></a>';
}
else if (overAllStatus == 'greenN') {
rows[lastRowClicked].cells[0].innerHTML = '<a class="modalInput" rel="#flagsSummary" style="cursor:pointer"><img src="/FatcaOne_0/static/images/circleGreen.png" width="20" height="20"></a>';
}
comments = $('#comments').val();
$("body").trigger(esc);
$("#save1").trigger('click');
redListSize = 0;
yellowListSize = 0;
console.log("save clicked");
});
当变量
overAllStatus
的值是JSt控制台中测试的yellow
时,并且在单击“保存”按钮之前,我在控制台中看到了这个值:> overAllStatus
"yellow"
> overAllStatus == 'yellow'
true
我只看到控制台上印有“单击保存”。似乎测试条件
(overAllStatus == "yellow")
中的代码未执行。我不明白为什么。 最佳答案
尝试用此代码替换您的代码,并查看“click”回调中“overAllStatus”具有什么值
$('#save').click(function () {
console.log("overAllStatus", overAllStatus); //use this to check the value of overAllStatus
if (overAllStatus == 'red') {
rows[lastRowClicked].cells[0].innerHTML = '<a class="modalInput" rel="#flagsSummary" style="cursor:pointer"><img src="/FatcaOne_0/static/images/circleRed.png" width="20" height="20"></a>';
}
else if (overAllStatus == "yellow") {
rows[lastRowClicked].cells[0].innerHTML = '<a class="modalInput" rel="#flagsSummary" style="cursor:pointer"><img src="/FatcaOne_0/static/images/circleYellow.png" width="20" height="20"></a>';
console.log('Over all status is yellow.');
}
else if (overAllStatus == 'greenR') {
rows[lastRowClicked].cells[0].innerHTML = '<a class="modalInput" rel="#flagsSummary" style="cursor:pointer"><img src="/FatcaOne_0/static/images/circleGreenHollow.png" width="20" height="20"></a>';
}
else if (overAllStatus == 'greenN') {
rows[lastRowClicked].cells[0].innerHTML = '<a class="modalInput" rel="#flagsSummary" style="cursor:pointer"><img src="/FatcaOne_0/static/images/circleGreen.png" width="20" height="20"></a>';
}
comments = $('#comments').val();
$("body").trigger(esc);
$("#save1").trigger('click');
redListSize = 0;
yellowListSize = 0;
console.log("save clicked");
});