你好,我有这样的链接,例如模拟印刷机在使用链接按键
<a href"http://google.es">Link</a>
是否有使用Javascript或类似的任何方式,当我按下例如在键盘数字5 It's一样如果我用鼠标按下链接? 感谢
你好,我有这样的链接,例如模拟印刷机在使用链接按键
<a href"http://google.es">Link</a>
是否有使用Javascript或类似的任何方式,当我按下例如在键盘数字5 It's一样如果我用鼠标按下链接? 感谢
你可以使用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>
你可以在jQuery中使用的按键事件
$(function() {
$(document).keypress(function(e) {
if (e.which === 53){
location.href = "http://google.es";
}
});
});
这是关键5,如果你想改变的关键给予ASCI值该键
您可以使用鼠标事件。 –