6つの入力ボックスがあり、100までの入力ボックスがあります.100にputを追加しない場合や、入力が空の場合、ボタンをクリックするとアラートが表示されます。これまでは、合計が正しくない場合は警告を受け取ることができますが、空欄の場合は通知を受け取ることはできません。フォーマルの妥当性確認
HTML
<fieldset>
<input type="text" name="qty" oninput="findTotal()" id="qty1" class="hvr-pop" required/>
<input type="text" name="qty" oninput="findTotal()" id="qty2" class="hvr-pop" required/>
<input type="text" name="qty" oninput="findTotal()" id="qty3" class="hvr-pop" required/>
<input type="text" name="qty" oninput="findTotal()" id="qty4" class="hvr-pop" required/>
<input type="text" name="qty" oninput="findTotal()" id="qty5" class="hvr-pop" required/>
<input type="text" name="qty" oninput="findTotal()" id="qty6" class="hvr-pop" required/>
</fieldset>
<button type="button" class="weightageButton" onclick="validateTotal()">TOTAL WEIGHTAGE</button>
<output type="text" name="total" id="total" class="hvr-pop" readonly value="Must total 100"></output>
Javascriptを
for(var i=0; i<arr.length;i++){
if(parseInt(arr[i].value) === null || score > 100 || score < 100) {
alert("Please make sure each weightage is filled in and the total adds up to 100.");
$('#form1').find('input').val('');
$('#form1').find('#total').val('');
return false;
}
}
}
完璧、ありがとう! – invincibleme
あなたは大歓迎です:) –