Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- react jsx if
- spring builder
- react Quill
- javascript 함수
- react link
- Javascript
- 텍스트가 많은 경우
- springbatch chunk
- react quill custom
- spring
- JPA Insert
- Spring JPA
- react Page
- SpringBatch 스키마
- react forwardRef
- Spring DTO
- react react-router-dom v6
- Spring CORS
- javascrpit 기초
- Docker Windows 설치
- 코드 중복제거
- spring security
- editor Quill
- step 테이블
- react
- JPA Update\
- javascript 기초
- Spring Controller return
- springbatch
- Spring Entity
Archives
- Today
- Total
천천히 알아보는 코딩공부
javascript submit event 본문
input type submit 기본 이벤트를 막는 코드
const loginInput = document.querySelector("#login-form input");
const loginForm = document.getElementById("login-form");
function onLoginSubmit(event) {
event.preventDefault();
// 기본 이벤트를 막아줌
const username = loginInput.value;
console.log(username);
console.dir(event);
// event element 볼수 있음.
}
loginForm.addEventListener("submit", onLoginSubmit);
※ event 안에 console.dir(event) 할 시 event 에 대한 argument를 보여준다
Submit 이벤트 발생 시 해당 form 숨김 처리 및 글자 출력
const LoginForm = document.querySelector("#Login-form");
const LoginInput = document.querySelector("#Login-form input");
const greeting = document.querySelector("#greeting")
const HIDDEN_CLASSNAME = "hidden";
function onLoginSubmit(event) {
event.preventDefault();
LoginForm.classList.add(HIDDEN_CLASSNAME);
const username = LoginInput.value;
localStorage.setItem("username", username);
// localstorage 에 저장해서 새로고침후에도 가져올수 있게
greeting.innerText =`Hello ${username}`;
greeting.classList.remove(HIDDEN_CLASSNAME);
}
LoginForm.addEventListener("submit",onLoginSubmit);
※ 변수 + 변수 = 'Hello {$username}'; 가능 = "Hello" + username;
더보기
css
.hidden
{
display: none;
}
html
<body>
<form id = "Login-form">
<input required maxlength="15" type = "text" placeholder="what is your name?"/>
<!-- <button>Log in</button> -->
<input type="submit" value="Log In"/>
</form>
<h1 id = "greeting" class ="hidden"></h1>
<a href = "http://www.naver.com"> go to naver</a>
<script src = "app.js"></script>
</body>
'JavaScript > Event' 카테고리의 다른 글
javascript click event (0) | 2022.03.24 |
---|
Comments