admin管理员组文章数量:1287182
$(document).keypress(function(event) {
// +
if (event.which == 43) {
// ...
}
}
HTML
<input type="button" value="+" name="plus">
How can I trigger the keypress method with + when clicking the button?
$('input[name="plus"]').click(function(){
// ??? How to go further ???
})
$(document).keypress(function(event) {
// +
if (event.which == 43) {
// ...
}
}
HTML
<input type="button" value="+" name="plus">
How can I trigger the keypress method with + when clicking the button?
$('input[name="plus"]').click(function(){
// ??? How to go further ???
})
Share
Improve this question
edited Jun 1, 2020 at 16:21
Brian Tompsett - 汤莱恩
5,89372 gold badges61 silver badges133 bronze badges
asked Jul 1, 2011 at 13:50
powtacpowtac
41.1k28 gold badges118 silver badges172 bronze badges
2 Answers
Reset to default 8Here you go
var e = jQuery.Event("keypress");
e.which = 43; // # Some key code value
$(document).trigger(e);
Src: Definitive way to trigger keypress events with 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();
}
});
本文标签: javascriptTrigger keypress on button clickStack Overflow
版权声明:本文标题:javascript - Trigger keypress on button click - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741245008a2364706.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论