Google 即搜即得文本字段
您知道当您开始在 Instant 中输入时,您想要的单词建议就会开始出现,而第一个建议是单词旁边的一些灰色文本?这就是我有兴趣尝试模仿的(在 javascript 中,更喜欢),但对于文本字段和文本区域。
我考虑获取当前插入符位置的 x 和 y 坐标,并将灰色文本放在那里。但是,我不确定这是否是最好的选择,因为如果我想将灰色文本放在句子中间,或者你有什么,那么文本的其余部分必须移动以腾出空间。更不用说我还没有找到一种好方法来获取文本字段或文本区域中插入符的 x 和 y 坐标。由于这些原因,这个选项似乎效率很低。
此外,代码不能与 Google 的代码相同或接近相同。我想要的另一项功能是让灰色文本出现在句子中间,而谷歌的代码不支持这一功能。因此,这需要包含在解决方案中。
有谁知道如何实现这一目标(或一些代码)?我已经思考这个问题有一段时间了,但还没有真正取得任何进展。
谢谢!
You know how when you start typing in Instant, the suggestions for words you want start to come up, and the #1 suggestion is some grey text beside the word? That is what I am interested in trying to mimic (in javascript, prefer), but for text fields and text areas.
I thought about getting the x and y coordinates of the current caret position, and placing the grey text there. However, I'm not sure if this is the best option, because if I want to place that grey text in the middle of a sentence, or what have you, then the rest of the text would have to be shifted over to make room. Not to mention the fact that I haven't yet found a good way to even get the x and y coordinates of the caret in a textfield or textarea. For these reasons, this option just seems inefficient.
Also, the code can not be the same or near the same as what Google has. One additional feature I want is having the grey text appear in the middle of sentences, which Google's code doesn't support. So, that would need to be included in the solution.
Does anyone have an idea (or some code) of how to achieve this? I have been pondering this for a while and haven't really gotten anywhere.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JQuery 有一个很棒的自动完成 插件。
JQuery has a wonderful autocomplete plugin.