안녕하세요 예를시뮬레이션 프레스 키
<a href"http://google.es">Link</a>
이 링크는 내가 예를 들어 누를 때 키보드의 숫자 5와 같은 키우면 것을 자바 스크립트 또는 유사한을 사용하는 방법이 있습니다 마우스로 링크를 누르면? 감사
안녕하세요 예를시뮬레이션 프레스 키
<a href"http://google.es">Link</a>
이 링크는 내가 예를 들어 누를 때 키보드의 숫자 5와 같은 키우면 것을 자바 스크립트 또는 유사한을 사용하는 방법이 있습니다 마우스로 링크를 누르면? 감사
당신이 keypress
이벤트를 결합하고 event.which
을 도청하고 해당 키를 누를 때 프로그래밍 방식으로 a
또는 링크 요소를 클릭 할 수 있습니다 jQuery를 $(document).keypress(function(event) { event.charCode == 53 ? window.open("google.es","_self") : console.log('another key'); });
시도해보십시오. jQuery 사용하기.
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
function checkKey(e) {
var code;
if (e.keyCode) code = e.keyCode;
if (code == 53) { // replace the 53 with the keycode of your choice.
$('#myLink').trigger("click");
}
}
</script>
</head>
<body onkeydown="checkKey(event);">
<button id="myLink" onclick="window.location.href= 'https://google.com'">Link</button>
</body>
</html>
키 코드 참조 : http://www.foreui.com/articles/Key_Code_Table.htm이
당신이 JQuery와의 키 누름 이벤트를 사용할 수 있습니다
$(function() {
$(document).keypress(function(e) {
if (e.which === 53){
location.href = "http://google.es";
}
});
});
해당 키
의 키주고의 ASCI 값을 변경하려면이 키 5입니다
마우스 이벤트를 사용할 수 있습니다. –