Notice
Recent Posts
Recent Comments
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
Archives
Today
In Total
관리 메뉴

A Joyful AI Research Journey🌳😊

JavaScript: onchange, onkeyup, blur 본문

💻Bootcamp Self-Study Revision✨/JavaScript, jQuery, Ajax

JavaScript: onchange, onkeyup, blur

yjyuwisely 2023. 5. 4. 14:03

onchange event is triggered when the input field loses focus and its value has been changed.

예시)

<div class="Sans form-floating text-muted mb-3 is-invalid">
    <input class="form-control" name="password" id="password"
        placeholder="비밀번호" type="password" required
        pattern="^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{8,}$"
        onchange="validatePassword()" />
    <label for="password">비밀번호 (영문 숫자 특수문자 조합, 8자리 이상)</label>
    <div class="valid-feedback">좋아요!</div>
    <div class="invalid-feedback">영문자, 숫자, 특수기호 조합으로 8자 이상으로
        입력하세요.</div>
</div>
//비밀번호 체크
console.log("Password check connect");
function validatePassword() {
	const passwordInput = document.getElementById("password");
	if (!passwordInput.checkValidity()) {
		passwordInput.classList.add("is-invalid");
		passwordInput.classList.remove("is-valid");
	} else {
		passwordInput.classList.add("is-valid");
		passwordInput.classList.remove("is-invalid");
	}
}



onkeyup event is triggered when a key is released after being pressed down while the input field has focus.

blur 
event is triggered when the input field loses focus.


참고: https://coding-restaurant.tistory.com/233


728x90
반응형
Comments