gpt4 book ai didi

javascript - 按下按键而不是单击按钮

转载 作者:行者123 更新时间:2023-12-03 05:55:48 25 4
gpt4 key购买 nike

尝试在按下回车键时刷新页面,而不是默认单击按钮。我假设由于不确定如何调用按钮而需要事件监听器。

  $(document).ready(function() {
function refresh (e) {
if(e.keyCode === 13){

}
}
$('body').on('keydown', refresh);
})
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<link rel="stylesheet" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="script.js"></script>
</head>
<body>
<div class='win'>
<button><a href="index.html" style="text-decoration:none">Play Again</a></button>
</div>
</body>
</html>

最佳答案

当您点击 keyCode 为 13ENTER 时,这应该可以刷新页面

$(document).keypress(function(e) {
if(e.which == 13) {
location.reload();
}
});

关于javascript - 按下按键而不是单击按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39934548/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com