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

前端 未结 3 1859
南笙
南笙 2020-12-09 08:59

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

相关标签:
3条回答
  • 2020-12-09 09:46

    Try this

    $('#textboxid').focus(function()
        {
           $(this).animate({'height': '185px'}, 'slow' );//Expand the textarea on clicking on it
           return false;
         });
    
    0 讨论(0)
  • 2020-12-09 09:56
    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 });
    });
    
    0 讨论(0)
  • 2020-12-09 09:57

    You can try something like this:

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

    where moo is your textarea.

    0 讨论(0)
提交回复
热议问题