gpt4 book ai didi

jquery - 嵌套 jQuery IF 语句不起作用

转载 作者:行者123 更新时间:2023-12-01 06:48:40 26 4
gpt4 key购买 nike

<input type="radio" name="CAT_Custom_332258_327" value="Standard" class="member-type" />
<input type="radio" name="CAT_Custom_332258_327" value="Youth" class="member-type" />
<input type="radio" name="CAT_Custom_332258_327" value="Family Add-On" class="member-type" />

<input type="radio" name="highflight" value="print" class="highflight-type" />
<input type="radio" name="highflight" value="digital" class="highflight-type" />
<input type="radio" name="highflight" value="printdigital" class="highflight-type" />

我有 2 组单选按钮和一个“金额”文本字段 (#Amount)。当我更改第二个单选按钮集 (.highflight-type) 中的选择时,它应该根据两个单选按钮集的值更新“金额”文本字段。

$(".highflight-type").click(function(){

if($(this).val()=="print") {
if($('.member-type').val()=="Standard") {
$('#Amount').val('35');
}
if($('.member-type').val()=="Youth") {
$('#Amount').val('35');
}
}

if($(this).val()=="digital") {
if($('.member-type').val()=="Youth") {
$('#Amount').val('10');
}
if($('.member-type').val()=="Standard") {
$('#Amount').val('25');
}
}
if($(this).val()=="printdigital") {
if($('.member-type').val()=="Standard") {
$('#Amount').val('50');
}
if($('.member-type').val()=="Youth") {
$('#Amount').val('35');
}
}
});

但是,当我在第一个单选按钮集 (.member-type) 中选择“Youth”并将第二个单选按钮更改为“digital”时,我得到的 #Amount 值为 25 美元,而不是 10 美元。当我更改 .highflight-type 单选按钮选择时,我使用警报来确认 DOM 中的 .member-type 值。

最佳答案

$('.member-type').val() 将始终返回第一个 .member-type 单选的 value按钮。

相反,您应该过滤单选按钮以查找选中的单选按钮,并获取该单选按钮的值:

var $types = $('.member-type');
var $amount = $('#Amount');
var pricing = {
print: {
Standard: 35,
Youth: 35
},
digital: {
Standard: 25,
Youth: 10
},
printdigital: {
Standard: 50,
Youth: 30
}
};

$(".highflight-type").change(function() {

if ( ! this.checked ) return;

$amount.val(
pricing[ this.value ][ $types.filter(':checked').val() ]
);
});

这是 fiddle :http://jsfiddle.net/C8kZq/

关于jquery - 嵌套 jQuery IF 语句不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18579488/

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