javascript - 使用 jQuery 自动扩展输入(输入文本)
问题描述
如何使输入类型自动扩展?该代码适用于 textarea 但不适用于输入类型文本框。
$('input').on({
input: function() {
var totalHeight = $(this).prop('scrollHeight') - parseInt($(this).css('padding-top')) - parseInt($(this).css('padding-bottom'));
$(this).css({
'height': totalHeight
});
}
});
input {
width: 200px;
height: 15px;
line-height: 15px;
min-width: 200px;
max-width: 300px;
transition: width 0.25s;
resize: none;
overflow: hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="myinput" runat="server" placeholder="Text" type="text" data-autosize-input='{ "space": 40 }' />
解决方案
推荐阅读
- arrays - 如何在 React 中渲染一组 Array 对象和图像?
- javascript - “keyup”事件和“keydown”被同一个事件处理程序调用
- python - 基于索引的行总和与 Numpy
- c# - 使用枢轴将行转换为列
- r - 将文本块读入 R 并出现解析错误
- .htaccess - 如何在末尾没有正斜杠的情况下重定向单个段 url?
- mongodb - MongoDB ShardingKey 错误:文档不包含模式的分片键
- c# - 实现简单 HTTP 服务器推送到 C# 客户端的最佳方法
- node.js - 在 Mocha 中运行测试之前未完成之前块中定义的函数
- python - 熊猫命令跳过第一个空列