[英]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);
$(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.