Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
テキスト入力ボックスのサイズと最大長をどのように一致させますか?maxlength属性とsize属性が整列せず、フォントの使用に依存しているのは非常に厄介です。
Example input:<input type="text" size="4" maxlength="4" />
助言がありますか?
私はそれが一致するとは思わず、ブラウザに大きく依存します。最善の策は、CSS を使用して入力の幅を設定することです。
<input type="text" maxlength="4" value="1234" /> input {width:30px;}
http://jsfiddle.net/BqEsd/67/
また、文字、フォント サイズ、および言語に基づいてサイズを変更する何らかの関数を考え出すこともできます。たとえば、このようなもの..
例:
http://jsfiddle.net/krishollenbeck/ohpy5L95/3/