如何模拟“输入键击"与Jquery一起使用“就像人类一样". [英] How Simulate "Enter Key Hit" Using With Jquery "Just Like A Human Do"

查看:88
本文介绍了如何模拟“输入键击"与Jquery一起使用“就像人类一样".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请首先查看此线程:
如何同时使用Javascript和; jQuery
并在该线程中查看此评论:

please see this thread first :
How Simulate "Enter Key Hit" Using With Both Javascript & Jquery
and check out this comment in that thread :

@RobG:
您可以从 特定的目标元素,但是浏览器可能无法正确对待它 就像用户输入一样.你不能骗他们,他们知道事件发生了 从.另请参阅创建和触发事件.

@RobG :
you can dispatch a keypress event with appropriate parameters from a particular target element, however browsers may not treat it exactly like user input. You can't fool them, they know where the event came from. See also Creating and triggering events.

@RobG是正确的.
浏览器可以通过以下代码识别我们的模拟:

@RobG was right.
browsers can recognize our simulation by these codes:

var e = jQuery.Event("keypress");
e.which = 13; //choose the one you want
e.keyCode = 13;
$("#theInputToTest").trigger(e);

有没有办法像人类一样模拟?

is there a way to simulate that just like a HUMAN DO?

推荐答案

不是来自纯JavaScript.如果您真的想模拟它,可以考虑使用WebDriver模拟真实的用户交互.

Not from straight javascript. If you really want to simulate it, look into using WebDriver to simulate real user interaction.

这不是您在正常网页的生命周期中将要执行的操作,它通常用于集成测试之类的其他目的.

This is not something you're going to be able to do in a normal web page's lifecycle though, it's generally used for other purposes such as integration testing.

这篇关于如何模拟“输入键击"与Jquery一起使用“就像人类一样".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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