CSS 弹性文本框

发布于 2025-01-07 05:09:19 字数 83 浏览 5 评论 0原文

我的要求是这样的。 我需要一个宽度为 5px 的文本框。当我在上面输入内容时,宽度应该增加。是否可以只使用CSS而不使用js

thnx

My requirement is this.
I need a text box with a width of 5px. As I type something on it the width should be increased. Is it possible to do using CSS only without js

thnx

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

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

发布评论

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

评论(2

情话已封尘 2025-01-14 05:09:19

ATM 仅使用 CSS 是不可能实现这一点的。

要实现此目的,您必须在每次击键时检查文本字段的当前内容宽度(使用其 onKeyUp 事件),然后相应地更改文本框的宽度。

ATM this is not possible with CSS only.

To achieve this you would have to check the current content width of the textfield on every keystroke in it (use the onKeyUp event of it) and then change the textbox' width accordingly.

南街女流氓 2025-01-14 05:09:19

嗯我只知道这个..

<script language="javascript">
function expand_textbox(s)
{
    s.size = s.size + 1;
}
</script>

<input type="text" size="20" name=txt onkeyup="expand_textbox(this)" >

试试吧..

hmm i only know like this one..

<script language="javascript">
function expand_textbox(s)
{
    s.size = s.size + 1;
}
</script>

<input type="text" size="20" name=txt onkeyup="expand_textbox(this)" >

try it..

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