Javascript 文本区域自动增长onkeyup
我正在使用此脚本Javascript 文本区域自动增长onkeyup,javascript,jquery,html,css,ajax,Javascript,Jquery,Html,Css,Ajax,我正在使用此脚本 jQuery.each(jQuery('textarea[data-autoresize]'), function() { var offset = this.offsetHeight - this.clientHeight; var resizeTextarea = function(el) { jQuery(el).css('height', 'auto').css('height', el.scrollHeight + offse
jQuery.each(jQuery('textarea[data-autoresize]'), function() {
var offset = this.offsetHeight - this.clientHeight;
var resizeTextarea = function(el) {
jQuery(el).css('height', 'auto').css('height', el.scrollHeight + offset);
};
jQuery(this).on('keyup input', function() {
resizeTextarea(this); }).removeAttr('data-autoresize');
});
});
这是我的html
<h:inputTextarea id="newUserIds" value="#{surveyAction.newUsers}"
cols="41" rows="10" onkeyup="AutoGrowTextArea(this)"
styleClass="animated">
<p:ajax event="blur" process="@this" immediate="true" />
</h:inputTextarea>
如何在javascript上定位特定的textarea,以便操作只在那里应用。当前选择器找不到textarea元素 将jQuery选择器从
textarea[data autoresize]
更改为#newUserIds
,或者更改textarea标记并添加属性data autoresize
(推荐):
改用内容可编辑的div。要设置后端组件的值,请使用输入类型=“隐藏”字段 见- CSS- 加价-
<div contenteditable="true" class="resizable" id="resizablePseudoInput">
</div>
您希望“自动调整大小”如何工作?键入时调整大小,以便没有滚动条?是否应在某些情况下停止调整大小(例如,高度达到视口高度)?它应该湿透吗?为什么要在keyup
上removeAttr(“数据自动调整大小”)
请确认呈现的HTML是否包含文本区域的数据自动调整大小
属性。看起来TO正在使用JSF,也许该属性会自动呈现为HTML?(顺便说一句:你的答案中仍然缺少。)
.resizable{
overflow-x:auto;
border:1px solid #AAA;
min-height: 50px;
resize: both;
}
<div contenteditable="true" class="resizable" id="resizablePseudoInput">
</div>