本文介绍了调整输入大小以适合其内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不在乎一个特定的技术,它可能是JS,CSS,甚至一些非标准和邪恶的html属性。我只想让输入
变得更大,如果用户在右边框上输入。
I do not care for a specific technology, it could be JS, CSS or even some unstandard and evil html attributes. I just want the input
to get bigger if user types over the right border.
推荐答案
也许别人有更好的方法,但你可以尝试这样:
Maybe someone else has a better way, but you could try this:
示例:
var input = document.getElementsByTagName('input')[0];
input.onkeypress = input.onkeydown = function() {
this.size = ( this.value.length > 10 ) ? this.value.length : 10;
};
这将它设置为最小大小为10,如果超过10个字符,则展开。
This sets it at a minimum size of 10 and expands if you go beyond 10 characters.
可能最适合使用固定宽度的字体:
Probably works best with a fixed width font:
input {
font-family:Courier;
}
这篇关于调整输入大小以适合其内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!