如果两个值是 NULL
或 ""
,我正在尝试使用 js 将 css 样式添加到我的 html。我有以下代码:
if (v.doctor_id === null || v.doctor_id === "") {
v.doctor_id = 0;
}
if (v.assistant_id === null || v.assistant_id === "") {
v.assistant_id = 0;
}
...
if (v.doctor_id = 0 && v.assistant_id = 0) {
html += '<td class="ci6 text-right" style="background-color: green;">' + $('.price').masked(v.app_price) + '</td>';
} else {
html += '<td class="ci6 text-right" style="background-color: red;">' + $('.price').masked(v.app_price) + '</td>';
}
我的两个值是 doctor_id
和 aasistant_id
。我正在检查两者是否为空或“”。
现在我总是得到红色的背景颜色。
答案 0 :(得分:2)
问题就在这里:
if (v.doctor_id = 0 && v.assistant_id = 0) {
您使用了错误的运算符使用 ==
或 ===
:
if (v.doctor_id === 0 && v.assistant_id === 0) {
html += '<td class="ci6 text-right" style="background-color: green;">' + $('.price').masked(v.app_price) + '</td>';
} else {
html += '<td class="ci6 text-right" style="background-color: red;">' + $('.price').masked(v.app_price) + '</td>';
}