作者:fanguobiao | 来源:互联网 | 2023-01-29 10:01
我们如何改进以下if-else
代码:
$(".rdo_confirm").change(function(){
if($(this).val() == "Y") {
$("#btn_save").attr("disabled",false);
} else {
$("#btn_save").attr("disabled",true);
}
});
adeneo..
12
您可以直接使用检查值,因为它返回一个布尔值
$(".rdo_confirm").on('change', function(){
$("#btn_save").prop("disabled", this.value !== "Y");
});
$(this).val() == "Y"
返回检查true
或false
.如果检查返回,
似乎你想传递,这意味着你只是否定支票.
使用原生的Javascript,结果就像是 .
作为一个属性,您也想使用false
true
this.value !== "Y"
disabled
prop()
1> adeneo..:
您可以直接使用检查值,因为它返回一个布尔值
$(".rdo_confirm").on('change', function(){
$("#btn_save").prop("disabled", this.value !== "Y");
});
$(this).val() == "Y"
返回检查true
或false
.如果检查返回,
似乎你想传递,这意味着你只是否定支票.
使用原生的Javascript,结果就像是 .
作为一个属性,您也想使用false
true
this.value !== "Y"
disabled
prop()