jquery input宽度自适应
html
input class="write" type="text" style="width: 50px">
jquery
$('body').on('input propertychange','.write', function() { var $this = $(this); console.log($this); var text_length = $this.val().length;//获取当前文本框的长度 var current_width = parseInt(text_length) *14;//该14是改变前的宽度除以当前字符串的长度,算出每个字符的长度 console.log(current_width); $this.css("width",current_width+"px"); });