随着键入更多类型,使 HTML 输入字体大小缩小
问题描述:
我有一个 3 个字符的 HTML 文本字段.如果用户键入 4 个字符,我希望缩小字体大小以适应四个字符.
I have an HTML text field that is 3 characters. If the user types 4 characters, I want the font size to shrink so that the four characters will fit.
Acrobat 对表单具有此行为.我想要 HTML 中的这种行为.
Acrobat has this behavior for forms. I want this behavior in HTML.
也就是说,如果我有一个包含 3 个字符的文本字段:
That is, if I have a text field with 3 characters:
用户输入 4,我希望文本缩小:
And the user types a 4, I want the text to shrink:
答
这在 HTML/CSS 中是不可能的 - 此解决方案使用 JS+JQuery
This is not possible with HTML/CSS - this solution uses JS+JQuery
发现这个:https://github.com/vxsx/jquery.inputfit.js演示:http://vxsx.github.io/jquery.inputfit.js/
<input type="text" name="younameit" id="input">
<script type="text/javascript">
$('#input').inputfit();
</script>