/* 姝ゆ??浠?extarea??楂?搴︽? height:100%; 缁ф?跨?跺??绱???楂?搴 ==> ?跺??绱?????涓?涓 position:relative; ?ㄤ?瀹?浣?textarea 椤甸??腑??杞藉?姣???娣诲??浜?pre??绛撅?pre??绛炬??互????绱?瀛??ㄧ??骞朵?涓????锛?浣??????ㄧ┖?达? 涓???display:none;浠?涔?绌洪?翠?涓????? ??浠?extarea?跺??绱???楂?搴︽????杩?pre??寮???(??extarea???㈠???ユ??瀛?锛???瀛?浼?琚?坊????re搴?涓???span??绛鹃??锛?浠ユ??ユ??寮?pre??楂?搴? 瑕??瑰??textarea??濮????剁??楂?搴︼??????瑰??pre??padding?煎?冲???椤甸?㈠??杞芥??re???㈡坊??
??绛炬??负浜?璁?re??绛惧??濮??舵??涓??搴 */ ;(function ($) { // Constructor function FT(elem) { this.$textarea = $(elem); this._init(); } FT.prototype = { _init: function () { var _this = this; // Insert wrapper elem & pre/span for textarea mirroring this.$textarea.wrap('
').before('

'); this.$span = this.$textarea.prev().find('span'); // Add input event listeners // * input for modern browsers // * propertychange for IE 7 & 8 // * keyup for IE >= 9: catches keyboard-triggered undos/cuts/deletes // * change for IE >= 9: catches mouse-triggered undos/cuts/deletions (when textarea loses focus) this.$textarea.on('input propertychange keyup change', function () { _this._mirror(); }); // jQuery val() strips carriage return chars by default (see http://api.jquery.com/val/) // This causes issues in IE7, but a valHook can be used to preserve these chars $.valHooks.textarea = { get: function (elem) { return elem.value.replace(/\r?\n/g, "\r\n"); } }; // Mirror contents once on init this._mirror(); } // Mirror pre/span & textarea contents ,_mirror: function () { this.$span.text(this.$textarea.val()); } }; // jQuery plugin wrapper $.fn.flexText = function () { return this.each(function () { // Check if already instantiated on this elem if (!$.data(this, 'flexText')) { // Instantiate & store elem + string $.data(this, 'flexText', new FT(this)); } }); }; })(jQuery);