답변 3개 / 댓글 1개
채택된 답변
+20 포인트
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>
요런식으로 짜보니까 되긴하는데 마지막에 스페이스 같은 키를 한번더 입력해야
다른페이지로 랜딩이 되네요 ㅠ 방법이 없을까요?
답변을 작성하려면 로그인이 필요합니다.
근데 input 타입이 text인데요
입력한 값을 가져오는 방법이
<input type="text" id="typing" name="typing" class="typing" style="width:100%" >
var b = document.getElementById("typing").innerText
이런식으로 하면 맞나요?