你如何使用jQuery模拟打字? [英] How do you simulate typing using jQuery?

查看:125
本文介绍了你如何使用jQuery模拟打字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

click()可以用来触发元素的点击事件,是否有任何方法来模拟字符串的输入?

解决方案

您正在寻找一种方法来触发与输入相关联的事件,或者您想将文本附加到容器,以使其看起来像某人在打字?如果你正在寻找事件,那么@Nick在建议触发事件的方法是绝对正确的。如果是后者,您将需要使用一个计时器来替换容器的text / html,并使用文本的连续子字符串。如果文本非常长,您可以通过附加包含每个字母的连续 span 元素来获得更好的效果 - 这将减少文本被替换时的闪烁,

编辑:我要添加一个示例,但事实证明有一个插件已经: jTypeWriter


Like how the click() can be used to trigger a click event on an element, is there any way to simulate the typing of a string?

解决方案

Are you looking for a way to trigger the events associated with typing or do you want to append text to a container so that it looks like someone is typing? If you're looking for the events, then @Nick is absolutely correct in suggesting the methods for triggering the event. If the latter, you'll want to use a timer to replace the text/html of the container with successive substrings of your text. You might be able to get a better effect by appending successive span elements containing each letter if the text is very long -- this would reduce flashing as the text gets replaced and the layout changes momentarily.

EDIT: I was going to add an example, but it turns out there's a plugin for that already: jTypeWriter.

这篇关于你如何使用jQuery模拟打字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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