input 태그에 일정 문구를 치면 웹페이지를 이동시키고 싶습니다
본문
일정한 문구를 치면 다른 페이지로 이동시키고 싶은 상황인데요 ㅠ 홈페이지 이용자가 input type ="text"의 input 태그에다가 미리 제시된 문구와 같은 문구를 타이핑 하면 다른 페이지로 이동시키고 싶습니다. 혹시 알려주실수 있는 분 계신가요 |
답변 3
input박스에 keypress 이벤트로 키 누를때마다 이벤트를 일으키시고
if문으로 만약 정해진 문자와 같다면
window.location.href = "이동할 페이지"; 이런식으로 이동시켜주세요.
<div class="textTest">
크크크크
</div>
<div class="container">
<input type="text" id="typing" name="typing" class="typing" style="width:100%" onkeypress="eventonkeypress()" >
</div>
<script type="text/javascript">
<!--
function eventonkeypress(){
var b = document.getElementById("typing").value;
if( b =="크크크크"){
window.location.href='http://www.naver.com/';
};
};
-->
</script>
요런식으로 짜보니까 되긴하는데 마지막에 스페이스 같은 키를 한번더 입력해야
다른페이지로 랜딩이 되네요 ㅠ 방법이 없을까요?
$("#typing").val();
하면 됩니다.
답변을 작성하시기 전에 로그인 해주세요.