검색엔터 html
<div class="search">
<input class="form-control me-sm-2" type="text" placeholder="검색" id="article-search">
<button class="btn btn-secondary my-2 my-sm-0" type="submit">
<i class="fas fa-search"></i>
</button>
</div>
검색엔터 JS
1. key 값이 entet인지 확인 엔터키를 눌렀을 때 실행된다.
2.event.preventDefault();페이지가 새로고침되는 동작을 막는다.
3.searchFilter 검색 필터링을 즉 실행을 해준다( );
function handleSearch(event) {
if (event.key === 'Enter') {
event.preventDefault();
searchFilter();
}
}
댓글