【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");
    });
})

posted @ 2022-04-26 15:04  郭祺迦  阅读(1135)  评论(0)    收藏  举报