文本区域自动换行

发布于 2024-09-07 07:53:44 字数 201 浏览 2 评论 0原文

使用 jQuery,如何制作一个文本区域,在光标接近末尾时插入文本时自动添加新行。

文本区域的宽度是通过 CSS 动态完成的(例如,#myTextArea { width: 80%; }),因此我无法执行诸如计算每行中的字符之类的操作。

我不需要非 JS 解决方案,因为无论如何,文本区域的内容只能被 JavaScript 看到。

Using jQuery, how can I make a textarea that automatically adds a new line when inserting text when the cursor is near the end.

The width of the textarea is dynamically done via CSS (e.g., #myTextArea { width: 80%; }) so I can't do anything like counting the characters in each line.

I don't need a non-JS solution since the content of the textarea is only ever seen by JavaScript anyways.

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

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

发布评论

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

评论(1

つ可否回来 2024-09-14 07:53:44

这是一个非常令人讨厌的问题,需要尝试解决。我会选择两条路中的任意一条。 1 直接使用文本区域,或者 2 使用漂亮的 jQuery 编辑器,使文本看起来很漂亮。

This is a really nasty problem to try and solve. I'd be going down either 1 of 2 pahts. 1 just use the text area as is or 2 using a nice jQuery editor which makes the text look nice.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文