私はjsで検証をしようとしていますが、入力と選択があり、それぞれの下にアラートがあり、入力値が12より小さいとアラートが表示され、ユーザーが離れるとフォームの最後に無効なボタンがあり、入力の値が== 12かselectがnullでない場合は有効になりますが、入力用に何か試してみましたが、わかりません同じ機能で選択条件を置く方法を、ここに私のコードです:jsでフォームの検証
$('#requiredInput').keyup(function() {
if (document.getElementById("requiredInput").value.length == 12)
{
document.getElementById("requiredAlert").style.display = 'none';
document.getElementById("disabledButton").disabled = false;
} else if ( document.getElementById("requiredInput").value.length != 12) {
document.getElementById("requiredAlert").style.display = 'block';
document.getElementById("disabledButton").disabled = true;
}
});
p{
display:none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="requiredInput">
<p id="requiredAlert">Please fill out this field</p>
<select id="requiredSelect">
<option>Hi</option>
</select>
<p id="requiredSelectAlert">Please select</p>
<button disabled id="disabledButton">Submit</button>
あなたは選択とはどのように過ごしたいですか?選択がnullでない場合は何かしますか? –
@MarioJuniorTorresPerezはい、selectがnullでなく入力値が= 12の場合、ボタンが有効になります。それ以外の場合、警告が表示され、ボタンは無効のままです。 – jessica