/*
Auto-growing textareas; technique ripped from Facebook
(Textarea need set style "overflow:hidden" under IE)
*/
(function($) {
function times(string, number) {
for (var i = 0, r = ''; i < number; i ++) r += string;
return r;
}
$.fn.autogrow = function(options) {
this.filter('textarea').each(function() {
this.timeoutId = null;
var $this = $(this), minHeight = $this.height();
var shadow = $('<div></div>').css({
position: 'absolute',
wordWrap: 'break-word',
top: 0,
left: -9999,
display: 'none',
width: $this.width(),
fontSize: $this.css('fontSize'),
fontFamily: $this.css('fontFamily'),
lineHeight: $this.css('lineHeight')
}).appendTo(document.body);
var update = function() {
var val = this.value.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/&/g, '&')
.replace(/\n$/, '<br/> ')
.replace(/\n/g, '<br/>')
.replace(/ {2,}/g, function(space) { return times(' ', space.length -1) + ' ' });
shadow.html(val);
$(this).css('height', Math.max(shadow.height(), minHeight));
}
var updateTimeout = function() {
clearTimeout(this.timeoutId);
var that = this;
this.timeoutId = setTimeout(function(){ update.apply(that); }, 100);
};
$(this).change(update).keyup(updateTimeout).keydown(updateTimeout);
update.apply(this);
});
return this;
}
})(jQuery);
使用例子:
<!DOCTYPE HTML>
<html>
<head>
<script src="jquery.js"></script>
<script src="jquery.autogrow.textarea.js"></script>
<script type="text/javascript" language="javascript">
$(function() {
$("textarea").autogrow();
});
</script>
</head>
<body>
<textarea id="t1" style="overflow:hidden"></textarea>
</body>
</html>
分享到:
相关推荐
Textarea Autosize:根据内容的大小自动调整Textarea
基于jQuery的“autoresize”插件自动改变textarea大小!当textarea输入到最后一行,会自动添加一行的大小!也就是把textarea高度改变的增加一行的高度!
Textarea自动调整大小自动将textarea调整为其内容的大小。安装$ npm install @github/textarea-autosize用法必须在<textarea>上显式激活自动调整大小的行为。 import autosize from '@github/textarea-...
textarea 自适应大小 兼容Chrome ie等浏览器,自动调整大小
自动调整大小的textarea </title> <meta charset = “utf-8” /> <style type = “text/css”> .editable{cursor:text; font-size:13px; color:#003366;width:80px;line-height:20px;height:20px;...
Textarea-自动调整大小自动调整文本区域的大小步骤1: 在页面底部包含 textarea-autoresize.min.js 第2步: 给要自动调整大小的 textarea(s) 类“textarea-auto-resize” 第 3 步: 利润
文本框根据输入内容调整大小
flex 制作的文本框组件,能够根据加载的字符串长度,自动调整文本框大小。将源码导入Flash builder即可使用。
如果该字段可调整大小,则新大小将被视为最小高度 安装 npm install fit-textarea 设置 // This module is only offered as a ES Module import fitTextarea from 'fit-textarea' ; < textarea rows =" 3 " >...
textarea自动调整大小 用法 您可以使用css选择器。 AutoSize.resize("#mytext") ; 演示版
特别是input和textarea,并且在textarea右下角还有...取消表单项聚焦时产生的黄色边框: 代码如下: input,button,select,textarea{outline:none} 取消textarea的拖动改变大小的功能: 代码如下: textarea{resize:none}
自动调整文本区域的大小以适合值 例子 用法 JS npm install storm-textarea 要么使用es6 import import Textarea from 'storm-textarea'; Textarea('textarea'); 异步浏览器加载(使用/ dist文件夹中的....
元素,它会自动调整其内容的高度。 用法 import { AutoTextArea } from 'react-auto-textarea' export const SomeComponent = () => { const [someValue, setValue] = React.useState('') const textAreaProps = {...
textarea自动调整大小 这是一个jQuery插件,用于根据用户输入垂直调整文本区域并控制CSS中的任何表示形式。 没有使用克隆或幽灵元素。 :winking_face: 那么为什么要建立这个? 许多解决方案都不流畅。 在某些情况下...
Vue Textarea自动增长指令 Vue指令,用于自动增加和缩小文本区域的高度。 特征 键入时调整高度 加载时设置初始高度 调整复制和粘贴的高度 隐藏textarea的可见性时调整高度(在隐藏textarea并稍后显示时呈现页面时很...
jQuery 自动调整大小 jQuery 插件,用于在焦点、模糊、键盘或窗口调整大小时自动调整文本区域的大小。 选项 appendToElement :[Default: 'body'] 设置此值以将克隆元素附加到您选择的任何元素。 defaultRowCount : ...
ng.cork.ui.textarea-自动调整大小 用于根据用户输入或程序更改调整文本区域大小的 AngularjS 组件 入门 将ng.cork.ui.textarea-auto-resize添加到您的项目中。 通过凉亭: $ bower install --save ng.cork.ui....
React评论框 ... 使用textarea获取输入,但在textarea的顶部覆盖一个div,该样式用于设置文本的不同部分的样式。 发展 - npm install node devServer // open localhost:3000 in your favorite browser
jquery.textareaAutoSize 简单的 jQuery 插件自动调整内容的 textarea 大小。如何使用 $ ( 'textarea' ) . textareaAutoSize ( { min_height : 30 , // Default: 30 max_height : 100 // Default: 100} ) ;作者...