【layUI杂记】layUI之使input文本框随其中内容而变化长度的方法
$(function () {
//propertychange监听input里面的字符变化,属性改变事件
$('.zy-price').bind('input propertychange', function () {
var $this = $(this);
console.log($this);
var text_length = $this.val().length;//获取当前文本框的长度
var current_width = parseInt(text_length) * 16;//该16是改变前的宽度除以当前字符串的长度,算出每个字符的长度
console.log(current_width);
$this.css("width", current_width + "px");
});
})
本文来自博客园,作者:郭祺迦,转载请注明原文链接:https://www.cnblogs.com/guojie-guojie/p/16194869.html