我想在按键和点击时触发一个功能
I'd like to trigger a function on key and on click
我目前有一个函数 运行 当点击计算按钮时。
<button class="hvr-shrink" type="submit" value="submit" id="submit"> Calculate </button>
我想要函数 运行s 当我不仅点击提交按钮而且点击 ENTER KEY
功能完美,只是希望它在用户点击回车时也能正常工作
<html>
<head>
<title>Project</title>
<link href="../CSS files/style.css" rel="stylesheet" type="text/css">
<link href="../CSS files/hover.css" rel="stylesheet" type="text/css">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700,800' rel='stylesheet' type='text/css'>
</head>
<body>
<div id="home">
<a href="home.html">
<img class="hvr-shadow" src="../../misc/hoem.png" id="homeicon">
</a>
</div>
<h1>Geometric Sequence</h1>
<h2>Find any term of a Geometric Sequence</h2>
<input id="firstTerm" placeholder="First Term?">
<input id="nTerm" placeholder="Nth Term?">
<input id="commonR" placeholder="Common Ratio?">
<button class="hvr-shrink" type="submit" value="submit" id="submit"> Calculate </button>
<p id="term"> </p>
</div>
<script type="text/javascript" src="../math fxn (js)/geoseq.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.6.0/firebase.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</body>
</body>
将此代码添加到您的页面:
<script>
$(function(){
$('input#commonR').keypress(function(event) {
var keycode = event.keyCode || event.which;
if(keycode == '13') {
$('#submit').click();
}
});
}); //END document.ready
</script>
查看我在 mate 上工作的 fiddle,让我知道这是否是您需要的,让我们将其更新为您想要的。 . . https://jsfiddle.net/e2nf73bu/1/
$(document).on('keypress',function(event){
if ( event.which == 13 ) {
$('#submit').click()
}
})
我目前有一个函数 运行 当点击计算按钮时。
<button class="hvr-shrink" type="submit" value="submit" id="submit"> Calculate </button>
我想要函数 运行s 当我不仅点击提交按钮而且点击 ENTER KEY
功能完美,只是希望它在用户点击回车时也能正常工作
<html>
<head>
<title>Project</title>
<link href="../CSS files/style.css" rel="stylesheet" type="text/css">
<link href="../CSS files/hover.css" rel="stylesheet" type="text/css">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700,800' rel='stylesheet' type='text/css'>
</head>
<body>
<div id="home">
<a href="home.html">
<img class="hvr-shadow" src="../../misc/hoem.png" id="homeicon">
</a>
</div>
<h1>Geometric Sequence</h1>
<h2>Find any term of a Geometric Sequence</h2>
<input id="firstTerm" placeholder="First Term?">
<input id="nTerm" placeholder="Nth Term?">
<input id="commonR" placeholder="Common Ratio?">
<button class="hvr-shrink" type="submit" value="submit" id="submit"> Calculate </button>
<p id="term"> </p>
</div>
<script type="text/javascript" src="../math fxn (js)/geoseq.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.6.0/firebase.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</body>
</body>
将此代码添加到您的页面:
<script>
$(function(){
$('input#commonR').keypress(function(event) {
var keycode = event.keyCode || event.which;
if(keycode == '13') {
$('#submit').click();
}
});
}); //END document.ready
</script>
查看我在 mate 上工作的 fiddle,让我知道这是否是您需要的,让我们将其更新为您想要的。 . . https://jsfiddle.net/e2nf73bu/1/
$(document).on('keypress',function(event){
if ( event.which == 13 ) {
$('#submit').click()
}
})