2013-03-07 65 views
0

我正在使用名为“jQuery Autosize!”的插件。在我的textareas。我如何使它自动调整我的服务器端生成的textareas,因为它们在页面已经加载时生成。使用jQuery向服务器端生成的textarea添加autoresize

这是生成服务器端textareas的代码。 resultErrorObj.node_html包含服务器端生成的textarea,如下所示。

$(document).ready(function() { 
$("#postUpdate").submit(function(event){ 
     // setup some local variables 
     var $form = $(this), 
      // let's select and cache all the fields 
      $inputs = $form.find("input"), 
      // serialize the data in the form 
      serializedData = $form.serialize(); 
     // let's disable the inputs for the duration of the ajax request 
     $inputs.attr("disabled", "disabled"); 
     // fire off the request to /form.php 
     $.ajax({ 
      url: base_url + "ajax/post_status_update", 
      type: "post", 
      data: serializedData, 
      // callback handler that will be called on success 
      success: function(response, textStatus, jqXHR){ 
        var resultErrorObj = jQuery.parseJSON(response); 
        if (resultErrorObj.status == 1) 
        {   $(resultErrorObj.node_html).hide().insertAfter('#activitiesStream').slideDown('fast'); 
      } 
      else 
      { 
       alert(resultErrorObj.error); 
      } 
      }, 
      // callback handler that will be called on error 
      error: function(jqXHR, textStatus, errorThrown){ 
       // the error 
       alert("Error here " + errorThrown); 
      }, 
      // callback handler that will be called on completion 
      // which means, either on success or error 
      complete: function(){ 
       // enable the inputs 
       $inputs.removeAttr("disabled"); 
      } 
     }); 

     // prevent default posting of form 
     event.preventDefault(); 
}); 

});

谢谢!

+0

@timgws哎呀..我没看过那部分。谢谢。现在它工作得很好。 – 2013-03-07 09:26:04

回答