如何匹配文本输入框的大小和最大长度? [英] How do you match up the size and maxlength of a text input box?

查看:119
本文介绍了如何匹配文本输入框的大小和最大长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何匹配文本输入框的大小和最大长度?这是非常烦人的,maxlength和大小属性不排队,并依赖于字体的使用。

 示例输入: < input type =textsize =4maxlength =4/> 



有什么建议?

解决方案

<我不认为它会匹配,它将取决于浏览器。最好的办法是使用CSS设置输入的宽度。

 < input type =textmaxlength =4 value =1234/> 

input {width:30px;}

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

你也可以想出一些功能来根据字符,字体大小和语言来设置它的大小。例如:
$ b 示例:



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


How do you match up the size and maxlength of a text input box? It is very annoying that the maxlength and size attributes don't line up and are dependent on the font use.

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

Any suggestions?

解决方案

I don't think it will match up and it will very depending on the browser. Best bet is to use CSS to set the width of the input.

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

input {width:30px;}

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

You could also come up with some sort of function to size it based off of character, font size, and language. Something like this for example..

Example:

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

这篇关于如何匹配文本输入框的大小和最大长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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