input长度根据输入内容变化

来源:互联网 发布:园艺绿化网络热点词汇 编辑:程序博客网 时间:2024/05/21 14:47
$('input:not(.topinput)').bind('input propertychange', function() {    var $this = $(this);    console.log($this);    var text_length = $this.val().length;//获取当前文本框的长度    var current_width = parseInt(text_length) *19;//该19是改变前的宽度除以当前字符串的长度,算出每个字符的长度    if(current_width<10){        $this.css("width","20px");    }else{        $this.css("width",current_width+"px");    }});