jQuery的keydown触发器不工作 [英] jQuery keydown trigger not working

查看:104
本文介绍了jQuery的keydown触发器不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  $(function(){
) $(input)。keydown();
});

该脚本位于用户加载的每个页面上运行的chrome扩展,并且不起作用(即在Twitter网站上)。
但是,如果在chrome JavaScript控制台上执行相同的脚本,它将很好地工作。



您是否有任何关于如何从脚本中触发此事件的线索?

解决方案 div>

我修正了添加这行的代码,现在keydown甚至被正确触发了。

  var event = new KeyboardEvent 'KEYDOWN'); 
document.querySelector('[id =inputid]')。dispatchEvent(event);


I have this script running at the end of the document loading:

$(function () {
    $("input").keydown();   
});

The script is in a chrome-extension that run on each page the user loads and doesn't work (i.e. on twitter website). However, if the same script is executed on the chrome javascript console it work perfectly.

Do you have any clue about how to trigger this event from the script?

解决方案

I fixed the code adding this line and now the keydown even is triggered correctly

var event = new KeyboardEvent('keydown');
document.querySelector('[id="inputid"]').dispatchEvent(event);

这篇关于jQuery的keydown触发器不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆