我正在尝试根据此解决方案实现自动调整大小的文本字段 question
<input style="width:20px;" onkeypress="this.style.width = ((this.value.length + 1) * 5) + 'px';" ng-model="questionButtons[$index].title" type="text" class="edt_spn active" >
它工作正常但是当用户删除字符时宽度没有调整
<input style="width:20px;" onkeypress="this.style.width = ((this.value.length + 1) * 5) + 'px';" ng-model="questionButtons[$index].title" type="text" class="edt_spn active" >
最佳答案
尝试 onkeyup 事件。
<input style="width:20px;" onkeyup="this.style.width = ((this.value.length + 1) * 5) + 'px';console.log(this.value.length);" ng-model="questionButtons[$index].title" type="text" class="edt_spn active" >
关于Javascript:根据文本调整输入字段宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48898996/