2017. 3. 5. 12:05
반응형
JavaScript를 이용해도 되지만 제이쿼리를 이용하면 쉽게 단축키를 만들 수 있다.
input, textarea 등 입력폼에 커서가 있을 경우는 단축키가 작동되지 않도록 했다.
아래 예제는 g키를 누를 경우 경고창이 뜬다.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).on("keydown", function(e) {
if ( !($("input").is(":focus")) && !($("textarea").is(":focus")) ) {
if (e.which == 71) alert("g키");
}
});
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(document).keydown(function(e){
if( !($("input").is(":focus")) && !($("textarea").is(":focus")) ) {
if(e.which == 71) alert("g키");
}
});
});
</script>
반응형
'dev' 카테고리의 다른 글
[Ubuntu] Apache, MySQL, php 설치 (0) | 2017.04.17 |
---|---|
[Ubuntu] 자바 설치하기 (0) | 2017.04.17 |
PHP 실습할때 (0) | 2017.04.15 |
[Java] 소수(Prime Number) 출력하기 (0) | 2017.04.09 |
[Java] 로또번호 생성하기 (0) | 2017.03.01 |
[Java] 구구단 출력하기 (0) | 2017.03.01 |
[JavaScript] 로또번호 생성기3.0 (제외수 지정 가능) (1) | 2017.02.26 |
[JavaScript] 배열 섞기 (랜덤) (0) | 2017.02.25 |