gpt4 book ai didi

javascript - jQuery 必填字段循环。基于 CSS 类

转载 作者:行者123 更新时间:2023-11-28 13:06:29 26 4
gpt4 key购买 nike

我正在尝试找出一种方法来根据 <input class="required"> 遍历以下必填字段.目前我只评估循环中的第一个输入。我如何在这里使用循环来横穿dom并检查所有输入框?谢谢。我见过类似的例子,在我的具体情况下,我似乎无法让它们工作。

$("#howMuch").click(function () {
var numOfPeriods = 0;
//Validates for empty code only.
if ($('.required').val().length == 0) {
$('.modal').show();
$('.modal_content').text('Please fill in the Required Fields');
} else {
//Clear previous graph
clearGraph();
//Adjust the number of periods from years to month
numOfPeriods = yearToMonthAdj();
//Declare a variable for the final future value
var futureValue = createiRateGraphNoInterest(numOfPeriods);
//Test if were rich
testFVforMillionaire(futureValue);
}
});

最佳答案

您可以使用 .each() 在您的元素内循环,类 required
试试这个:

$('.required').each(function(index){
if($(this).val().length==0) {
$('.modal').show();
$('.modal_content').text('Please fill in the Required Fields');
} else {
//Clear previous graph
clearGraph();
//Adjust the number of periods from years to month
numOfPeriods = yearToMonthAdj();
//Declare a variable for the final future value
var futureValue = createiRateGraphNoInterest(numOfPeriods);
//Test if were rich
testFVforMillionaire(futureValue);
}
});

关于javascript - jQuery 必填字段循环。基于 CSS 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20082915/

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