为了账号安全,请及时绑定邮箱和手机立即绑定

用jQuery模拟按键

用jQuery模拟按键

慕尼黑8549860 2019-11-13 15:26:24
使用jQuery,单击链接时如何模拟(触发?)KeyPress?例如,当用户单击以下链接时:<a id="clickforspace" href="#">Click Here</a>然后,通过单击链接,就好像他们按下了键盘上的“空格键”一样。我假设是这样的:$("#clickforspace").click(function(e) {     e.preventDefault();     //... Some type of code here to initiate "spacebar" //                                      });关于如何实现这一目标的任何想法?
查看完整描述

3 回答

?
噜噜哒

TA贡献1784条经验 获得超7个赞

我相信这就是您要寻找的:


var press = jQuery.Event("keypress");

press.ctrlKey = false;

press.which = 40;

$("whatever").trigger(press);


查看完整回答
反对 回复 2019-11-13
  • 3 回答
  • 0 关注
  • 491 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信