【问题标题】:How do you match up the size and maxlength of a text input box?你如何匹配文本输入框的大小和最大长度?
【发布时间】:2013-02-01 16:06:23
【问题描述】:

如何匹配文本输入框的大小和最大长度?很烦人的是 maxlength 和 size 属性没有对齐并且依赖于字体的使用。

 Example input:<input type="text" size="4" maxlength="4" />

有什么建议吗?

【问题讨论】:

标签: html css forms


【解决方案1】:

我认为它不会匹配,并且很大程度上取决于浏览器。最好的办法是使用 CSS 来设置输入的宽度。

<input type="text" maxlength="4" value="1234" />

input {width:30px;}

http://jsfiddle.net/BqEsd/67/

您还可以想出某种函数来根据字符、字体大小和语言来调整它的大小。例如这样的事情..

示例:

http://jsfiddle.net/krishollenbeck/ohpy5L95/3/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-19
    • 1970-01-01
    • 2022-01-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多