Javascript 如果值为true,则追加数据
如果复选框值为true,我将尝试附加html数据Javascript 如果值为true,则追加数据,javascript,jquery,Javascript,Jquery,如果复选框值为true,我将尝试附加html数据 if ($('#telephonyeq1').is(":checked") != 'false') { $("telephony1 telephony2").html( 'Telephony: <span style="color: #37b400">' + $('#telephonyeq1').is(":checked") + '</span> Service Issues <
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>'
);
}
if($('telephonyeq1')是(“:checked”)!='false'){
$(“telephony1 telephony2”).html(
“Telephony:”+$(“#telephonyQ1”)。是(“:选中”)+
“服务问题”+telephony.value()+
“-受影响的用户:”+telephonyaffected.value()+
''
);
}
它始终附加数据,即使值为真或假,请提供任何建议/帮助?您可以直接执行以下操作:
if ($('#telephonyeq1').is(":checked")) {
...
}
因为true!=“true”
和true!==“真”
和假!=“假”
和假!==“false”
,当前代码无法按预期工作(因为您正在将布尔值与字符串进行比较)。您可以直接执行以下操作:
if ($('#telephonyeq1').is(":checked")) {
...
}
因为
true!=“true”
和true!==“真”
和假!=“假”
和假!==“false”
,您当前的代码无法按预期工作(因为您正在将布尔值与字符串进行比较)。如果($(''ThephoneyQ1')。is(“:checked”)!=false)
或者简单的这里缺少如果($('ThephoneyQ1')。is(“:checked”)
$(“telephony1 telephony2”)
或
,因为它需要是选择器if($(''.'telephonyq1')。is(“:checked”)!=false)
或simpleif($('.'telephonyq1')。is(“:checked”)
方法返回布尔谢谢!工作完美@tphil$(“telephony1 telephony2”)
此处缺少#
或
,因为它需要选择