我从脚本创建textarea扩展器,但之后,它不会扩展

我不知道标题是否正确。 我用一个脚本创建了一个带有5个textarea的表,其中class =“expand”。 当我写这个textarea扩展但后来不起作用。 在编写调用jquery插件后是否有方法? 在我没有创建textarea的情况下尝试之前,我在html文件中写道并且它有效。

(关于2 textarea的信息和示例:

http://blogs.sitepointstatic.com/examples/tech/textarea-expander/index.html http://jsfiddle.net/V2RLs/2/ (without class="expand") 

)但是当我在textarea写的时候它没有扩展。为什么?

这是我的脚本:

  $(document).ready(function() { var regex,v,l,c,b; $( "#wnd_Addparam" ).dialog({ autoOpen: false, height: 'auto', width: 350, modal: true, resizable:false, buttons: { "Add": function() { contapara=(parseInt(contapara)+1); document.getElementById("sorpara").innerHTML+="
  • "+txt_idparam.value+"
  • "; $('#formp').submit(); $( this ).dialog( "close" ); }, Cancel: function() { $( this ).dialog( "close" ); } }, close: function() { $( this ).dialog( "close" ); } }); $( "#btn_Addpar" ).click(function() { i=(parseInt(contapara)+1); $('#wnd_Addparam').append('
    TextIntegerFloatList of valuesRangeSelection (collapsed)Selection (expanded)Subimage selectionPolygon selectionHorizontal separator
    /form>'); $( "#wnd_Addparam" ).dialog( "open" ); });});

    插件扩展器..

     /** * TextAreaExpander plugin for jQuery * v1.0 * Expands or contracts a textarea height depending on the * quatity of content entered by the user in the box. * * By Craig Buckler, Optimalworks.net * * As featured on SitePoint.com: * http://www.sitepoint.com/blogs/2009/07/29/build-auto-expanding-textarea-1/ * * Please use as you wish at your own risk. */ /** * Usage: * * From JavaScript, use: * $().TextAreaExpander(, ); * where: *  is the DOM node selector, eg "textarea" *  is the minimum textarea height in pixels (optional) *  is the maximum textarea height in pixels (optional) * * Alternatively, in you HTML: * Assign a class of "expand" to any  * * Or assign a class of "expandMIN-MAX" to set the  * The textarea will use an appropriate height between 50 and 200 pixels. */ (function($) { // jQuery plugin definition $.fn.TextAreaExpander = function(minHeight, maxHeight) { var hCheck = !($.browser.msie || $.browser.opera); // resize a textarea function ResizeTextarea(e) { // event or initialize element? e = e.target || e; // find content length and box width var vlen = e.value.length, ewidth = e.offsetWidth; if (vlen != e.valLength || ewidth != e.boxWidth) { if (hCheck && (vlen  h ? "auto" : "hidden"); e.style.height = h + "px"; e.valLength = vlen; e.boxWidth = ewidth; } return true; }; // initialize this.each(function() { // is a textarea? if (this.nodeName.toLowerCase() != "textarea") return; // set height restrictions var p = this.className.match(/expand(\d+)\-*(\d+)*/i); this.expandMin = minHeight || (p ? parseInt('0'+p[1], 10) : 0); this.expandMax = maxHeight || (p ? parseInt('0'+p[2], 10) : 99999); // initial resize ResizeTextarea(this); // zero vertical padding and add events if (!this.Initialized) { this.Initialized = true; $(this).css("padding-top", 0).css("padding-bottom", 0); $(this).bind("keyup", ResizeTextarea).bind("focus", ResizeTextarea); } }); return this; }; })(jQuery); // initialize all expanding textareas jQuery(document).ready(function() { jQuery("textarea[class*=expand]").TextAreaExpander(); }); 

    该插件在document.ready上准备textareas,因此在document.ready触发后该类被赋予的任何textarea都不会受到插件的影响 – 但是,您可以直接调用插件而不是添加类:

     jQuery(".expand").TextAreaExpander(); 

    但是,你不应该在一个元素上运行两次TextAreaExpander,所以如果你有使用在document.ready上初始化的插件的textareas,请务必使用另一个类名来生成textareas – 或者你可以删除插件的最后几行。