我一直在对允许用户选择金额或选择其他金额的表单进行故障排除。点击后的其他金额将金额更改为 5 美元。我试图得到它,以便当用户从 5 更改金额时,它会将 amt = 更改为用户输入。
改变它的脚本部分
function setDonrAmount(id){
var amt = id.substring(10);
if( amt == 'Other' ){ amt = 5}
var others = id.substring(0,10);
$("button[id*="+others+"]").removeClass('active');
$('button#'+id).addClass('active');
$('input#donrAmountInput').val(amt);
$('input#donrAmountInput').change();
$('#donrReviewAmount').html(amt);
}
这里是实际的表格供引用。帮助将不胜感激。 https://secure.pva.org/site/c.ajIRK9NJLcJ2E/b.9381225/k.8668/FY2016_March_Congressional/apps/ka/sd/donorcustom.asp
最佳答案
我对 setDonrAmount()
进行了一些更新以处理自定义捐赠。
$("#donrAmountButtons").on("click", function() {
var amt = id.substring(10);
setDonrAmount(amt);
$('#donrAmount' + amt).addClass('active');
});
$("#donrAmountInput").on("focusout", function() {
setDonrAmount($("#donrAmountInput").val());
$('#otherAmount button').addClass('active');
});
function setDonrAmount(val) {
var amt = val || 0;
if (amt.length < 2 && amt < 5)
amt = 5;
$('input#donrAmountInput').val(amt);
$('input#donrAmountInput').change();
$('#donrReviewAmount').html(amt);
$('#donrAmountButtons .active').removeClass('active');
}
关于javascript - jQuery 输入值故障排除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36340826/