Saturday 15 March 2014

jquery - Textarea autosize based on existing content can't work in chrome but can work in firefox -



jquery - Textarea autosize based on existing content can't work in chrome but can work in firefox -

i'm trying create textarea autogrow based on existing content.when content of textarea long,the textarea isn't autogrow show whole content in chrome.i should input '\n' ,and textarea show whole content. in firefox, textarea can show whole content.

html code:

<textarea id="currentvalue" class="auto-size" cols="110" onpropertychange="if(this.scrollheight&gt;80) this.style.posheight=this.scrollheight+5"></textarea>

when content long,onpropertychange can't work in chrome,but can work in firefox.

jquery code:

<script type="text/javascript" src="jquery.autosize.min.js"></script> <script type="text/javascript" src="jquery.autosize.input.js"></script> <script> $(function(){ $.getjson('data_get', function(ans){ //initial textarea , ensure textarea autogrow in vertical $('#currentvalue').val(ans.currentvalue); $('#currentvalue').css({ 'resize':'vertical' } ); . . . $('.auto-size').autosize({append: "\n"}); } }); </script>

i many files find answer,but find reply in jquery documentation.enter link description here

i modify script code this:

$('.auto-size').autosize({append: "\n"}).trigger('autosize.resize');

and when content long, textarea can show whole content in chrome(onpropertychange worked!!!).

jquery google-chrome firefox autosize

No comments:

Post a Comment