点击按钮时触发按键操作

5
$(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 ???
})
2个回答

8

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

我需要相反的方式:当我点击按钮时,应该虚拟触发一个按键事件。 - powtac

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接