越来越多的基于字符输入宽度的文本框 [英] Growing text box based on width of characters input

查看:79
本文介绍了越来越多的基于字符输入宽度的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个文本框,每当字母的宽度增加一个字母时,它就会增长。这是我正在尝试的。它不起作用。如果您有提示,请分享!



JavaScript:

  function MakeWidth(el){
el.style.width = parseFloat(el.value.clientWidth)}

HTML:

 < input id =Testtype =textstyle =width: 10px的;的onkeyup = MakeWidth(这)/> 


解决方案

尝试 size & 长度而不是 clientWidth & width



http://jsfiddle.net/eVd9b/5/

 函数MakeWidth(el){
el.size = parseInt(el.value.length);
}

这应该适合您的需求。

I am trying to create a text box that grows every time a letter is added to it by the width of the character. This is what I'm trying. It doesn't work. If you've got a hint, please share!

JavaScript:

function MakeWidth(el) {
        el.style.width = parseFloat(el.value.clientWidth) }

HTML:

<input id="Test" type="text" style="width: 10px;" onkeyup="MakeWidth(this)"/>

解决方案

Try size & length instead of clientWidth & width

http://jsfiddle.net/eVd9b/5/

function MakeWidth(el) {
    el.size = parseInt(el.value.length);
}

which should be suitable for your needs.

这篇关于越来越多的基于字符输入宽度的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆