How to change the number of rows in the textarea using jQuery

会有一股神秘感。 提交于 2019-11-27 02:35:23

问题


I have a textarea with 5 lines. I want to show only one line and on focus it should show remaining 4 lines.


回答1:


You can try something like this:

     $(document).ready(function(){

    $('#moo').focus(function(){
        $(this).attr('rows', '4');
    });
});

where moo is your textarea.




回答2:


jQuery(function($){
  $('#foo').focus(function(){
    $(this).attr('rows',5);
  }).blur(function(){
    $(this).attr('rows',1);
  });
});

Or, using less jQuery, less typing, and getting a hair more performance:

jQuery(function($){
  $('#foo')
    .focus(function(){ this.rows=5 })
    .blur( function(){ this.rows=1 });
});



回答3:


Try this

$('#textboxid').focus(function()
    {
       $(this).animate({'height': '185px'}, 'slow' );//Expand the textarea on clicking on it
       return false;
     });


来源:https://stackoverflow.com/questions/4417161/how-to-change-the-number-of-rows-in-the-textarea-using-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!