java的文本框如何回车键触发按钮,按下Enter键时触发HTML按钮

I am trying to make a button key "trigger" on a specific page using tampermonkey. Instead of using mouse click every time to click Button called "continue".

So when I click keyboard button "ENTER" this hover button should be automatically clicked, theres any ready to use code while I can just put this HTML code.

Thanks.

START MEMBERSHIP

解决方案

USING JQUERY

You can use easy jQuery to achieve it.

Just add a cdn given below in your main HTML page

And just open a script tags and copy paste this code.

$(document).keypress(function(event){

var keycode = (event.keyCode ? event.keyCode : event.which);

if(keycode == '13'){

$("#simplicityPayment-START").click();

}});

USING PURE JAVASCRIPT (NO EXTERNAL LIBRARY)

EDIT 1: As don't own the website & using tampermonkey. Okay so there is another way to achieve this, that is Pure JAVASCRIPT. it requires no CDN.

just Add this JAVASCRIPT.

window.addEventListener('keyup', function (e) {

if (e.keyCode === 13) {

var button = document.getElementById("simplicityPayment-START");

button.click();

}

}, false);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值