根据鼠标位置设置文本区域中的焦点和插入符位置,就好像用户单击了一样

发布于 2024-09-01 15:30:43 字数 336 浏览 2 评论 0原文

加载带有文本区域的页面后,如果鼠标光标位于该文本区域内,我希望该文本区域立即获得焦点。这是简单的部分,因为 onmousehover 处理程序可以设置焦点。

现在,我如何设置插入符的位置?我希望插入符位于用户使用鼠标单击以设置焦点/插入符时所在的位置。

基本用例是:

  1. 用户单击链接并等待(鼠标几乎不移动)
  2. 页面已交付,它仅包含一个大文本区域,充满文本
  3. 用户使用键盘输入
  4. 字符被插入到鼠标光标的正下方

今天,用户必须等到插入符号可见(位于文本区域的左上角),然后在键入之前单击以移动插入符号。

谢谢!

Once a page with a textarea is loaded, I want some textarea to have the focus immediatly if the mouse cursor is inside that textarea. This is the easy part because a onmousehover handler can set the focus.

Now, how to I also set the position of the caret? I would like the caret to be where it would be if the user had clicked using the mouse to set the focus/caret.

The basic use case is :

  1. User clicks on a link and waits (mouse barely moves)
  2. A page is delivered, it contains a big textarea only, full of text
  3. User types using keyboard
  4. Characters are inserted right below the mouse cursor

Today the user has to wait until the caret is visible (at the top left of the textarea) and then click to move the caret before typing.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文