繁体   English   中英

在按钮单击时触发按键

[英]Trigger keypress on button click

$(document).keypress(function(event) {
    // +
    if (event.which == 43) {
        // ...
    }
}

HTML

<input type="button" value="+" name="plus">

单击按钮时如何使用+触发 keypress 方法?

$('input[name="plus"]').click(function(){
    // ??? How to go further ???
})

给你 go

var e = jQuery.Event("keypress");
e.which = 43; // # Some key code value
$(document).trigger(e);

Src: 使用 jQuery 触发按键事件的确定方法

$(document).on('keypress',function(e) {
    if (e.keyCode == 43 || e.which == 43) {
        var identifier = e.target.id;
        console.log(e.target.id);
        $('#' + identifier).click();
    }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM