gpt4 book ai didi

javascript - 在 .val 中使用 if 语句创建函数

转载 作者:行者123 更新时间:2023-12-01 03:39:50 25 4
gpt4 key购买 nike

嗨,我不知道我是否正确。我正在做的是获取付款方式的值并将其传递给#editregistrationmodeof payment。

代码如下所示。

$("#editregistrationmodeofpayment").val(response.registration_mode_of_payment);

我想做的,但我遇到的问题是,如果 response.registration_mode_of_ payment 的值 = 'Monthly' 它将加载 Controller 我的。

我所做的已经看起来像这样。

$("#editregistrationmodeofpayment").val(response.registration_mode_of_payment, function(){  
if($(this).val() == 'Monthly') {
// Loads the controller
$("#editmodeofpayment").load('registration/assessModeofPayment/'+schoolyearId+'/'+response.gradelevel_id);
}
else { document.getElementById("editmodeofpayment").innerHTML = ""; }
});

可以这样做吗?

最佳答案

在我看来,response.registration_mode_of_ payment 持有您想要执行 if 语句的值。所以这应该可以做到:

if (response.registration_mode_of_payment === 'monthly') {
// Loads the controller
$("#editmodeofpayment").load('registration/assessModeofPayment/'+schoolyearId+'/'+response.gradelevel_id);
}
else { document.getElementById("editmodeofpayment").innerHTML = ""; }

关于javascript - 在 .val 中使用 if 语句创建函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43985509/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com