如何使用 jQuery 或 Javascript 跳过一个字符并将光标移动到输入中的下一个位置?

发布于 2024-10-06 03:52:42 字数 297 浏览 4 评论 0原文

您好,如何跳过一个字符并将光标移动到字符串中的下一个位置?例如,在输入字符串 123-4-789 中,当我在 4- 之间插入 5 时应变为 123-45-789 并且光标应位于 -7 之间,而不是 5>-。因此,如果插入 6,现在字符串应变为 123-45-6789

Hi how to skip a character and move the cursor to the next position in a string? For instance within the input string 123-4-789, when I insert 5 in between 4 and - it should become 123-45-789 and the cursor should be between - and 7 instead of 5 and -. So if 6 is inserted now string should become 123-45-6789.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

二智少女猫性小仙女 2024-10-13 03:52:42

也许看看 jQuery 的 A-Tools 插件

基本用法似乎是:

var cSelection = $("#myInput").getSelection();

/* might give, (start and end would be equal for normal caret operation) */
cSelection = { 'start': 0, 'end': 3, 'text': '123', 'length': 3 };

/* move caret to one place after end of selection */
$('#myInput').setCaretPos(cSelection.end + 1);

Perhaps have a look at the A-Tools plugin for jQuery.

Basic usage appears to be:

var cSelection = $("#myInput").getSelection();

/* might give, (start and end would be equal for normal caret operation) */
cSelection = { 'start': 0, 'end': 3, 'text': '123', 'length': 3 };

/* move caret to one place after end of selection */
$('#myInput').setCaretPos(cSelection.end + 1);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文