您的位置:首页 > 其它

input宽度随文字变化而变化

2016-11-16 16:57 204 查看
<input type="text" class="form-control">
<script>
var searchinput=$("input");
var textWidth = function (text) {
var sensor = $('<pre>' + text + '</pre>').css({display: 'none'});
$('body').append(sensor);
var width = sensor.width();
sensor.remove();
return width;
};
searchinput.unbind('keyup').bind('keyup', function () {
$(this).width(textWidth($(this).val() + 20));
});
</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: