您的位置:首页 > 其它

input长度根据输入内容变化

2017-11-01 09:10 1566 查看
$('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");
}
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: