我有一个问题:
document.querySelector('#target').click();我用click()方法实现了这个代码,但是我想点击目标按下enter键(keycode = 13),当然用javascript不是物理的。 那么怎么可能呢?
这是一个js小提琴,用于表示它是什么样的......
https://jsfiddle.net/当然,我想在开发人员模式下解决这个问题,所以在控制台中运行脚本。
请帮我解决这个问题。 提前致谢。
I've a problem :
document.querySelector('#target').click();I've this code with the click() method, but I would like to click on the target pressing the enter (keycode = 13), of course with javascript not physically. So how is it possible to do?
Here is a js fiddle, for representing how does it look like...
https://jsfiddle.net/Of course, I would like to solve this problem within the developer mode, so running the script in the console.
Please help me to solve this problem. Thanks in advance.
最满意答案
因为你使用jQuery,你可以使用:
$('#target').trigger({type: 'keypress',which: character.charCodeAt(13)});或者:
var ev = jQuery.Event("keypress"); ev.which = 13; $("#target").trigger(ev);希望这可以帮助。
Because you're using jquery you could use :
$('#target').trigger({type: 'keypress',which: character.charCodeAt(13)});Or also :
var ev = jQuery.Event("keypress"); ev.which = 13; $("#target").trigger(ev);Hope this helps.
更多推荐
problem,问题,click,电脑培训,计算机培训,IT培训"/> <meta name="description&
发布评论