input实时监听

 

//    使input文本框随其中内容而变化长度的方法
    $(function(){
        $('#aTest').bind('input propertychange', function() {
            var $this = $(this);
            console.log($this);
            var text_length = $this.val().length;//获取当前文本框的长度
            var current_width = parseInt(text_length) *13;//13是每个字符的长度
            console.log(current_width)
            $this.css("width",current_width+"px");
        });
    })

你可能感兴趣的:(input实时监听)