input 输入框宽度自适应
程序员文章站
2022-06-07 15:31:59
...
<html>
<title>input 输入框宽度自适应</title>
<body>
<input id="test" onkeypress="changeWidth()" type="text"/>
</body>
<script>
function changeWidth() {
var testLength = document.getElementById('test').value.length,
testDom = document.getElementById('test')
testDom.style.width = testLength*8 + 'px';
}
</script>
</html>