전자 메일 유효성을 검사하는 Materialize를 사용하여 양식을 만들려고합니다. 제출 버튼을 사용 중지 한 상태로 시작합니다. 전자 메일이 채워지고 유효성이 검사되면 제출 단추가 사용 중지되는 것이 이상적이며 사용자가 다음 단추를 클릭 할 수 있습니다. 여기 내 HTML은 다음과 같습니다Materialize 및 jQuery를 사용한 전자 메일 유효성 검사
여기<form id="survey">
<div class="input-group">
<p class="input-header">Enter Your Email</p>
<div class="input-block input-field">
<input id="email" type="text" name= "email" class="validate" required="" aria-required="true">
<label for="email">Email Address</label>
</div>
<br></br>
<a class="waves-light btn red lighten-2 disabled" id="submit">Submit
<i class="material-icons right">send</i>
</a>
<br></br>
<br></br>
<br></br>
</form>
는 자바 스크립트/jQuery를 수 있습니다 :
$(document).ready(function(){
$('.parallax').parallax();
$('body').on('click', '#submit', function() {
let decision = confirm('Are you sure you would like to submit your survey?');
if (decision) {
$.post('insert.php', $('#survey').serialize());
window.location.href = 'thankyou.php';
}
});
$('body').on('click', 'input', function() {
checkValidity($(this));
});
$('body').on('focusout', 'input', function() {
checkValidity($(this));
});
function checkValidity (current) {
let isValid = true;
if (!current.val()) {
isValid = false;
} else {
isValid = iteratatingForm(current);
}
const submit = $('#submit');
if (isValid) {
submit.removeClass('disabled');
} else {
if (!submit.hasClass('disabled')) {
submit.addClass('disabled');
}
}
}
function iteratatingForm (current) {
if (!document.forms['survey']['email'].value) return false;
return true;
}});
날 내가 잘못 알려주세요! 감사!
CodePen에서하시기 바랍니다 재현 할 수있는 일? :) – Toodoo
어쩌면 한번보세요 : https://stackoverflow.com/questions/1594952/jquery-disable-enable-submit-button – Toodoo
@Toodoo 이전에 키 입력을 시도했지만 작동하지 않았습니다. (CodePen! – Yikes