如果复选框值为 true,我将尝试附加 html 数据
if ($('#telephonyeq1').is(":checked") != 'false') {
$("telephony1 telephony2").html(
'Telephony: <span style="color: #37b400">' + $('#telephonyeq1').is(":checked") +
'</span> Service Issues <span style="color: #37b400">' + telephony.value() +
'</span> - Affected Users: <span style="color: #37b400">' + telephonyaffected.value() +
'</span>'
);
}
它总是附加数据,即使值是 true 或 false,请问有什么建议/帮助吗?
最佳答案
您可以直接执行:
if ($('#telephonyeq1').is(":checked")) {
...
}
因为 true != "true"
和 true !== "true"
和 false != "false"
和 false !== "false"
,您当前的代码无法按您的预期工作(因为您正在比较 bool 值与字符串)。
关于javascript - 如果值为 true 则追加数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49941432/