【问题标题】:How to change the number of rows in the textarea using jQuery如何使用jQuery更改文本区域中的行数
【发布时间】:2011-05-23 23:05:29
【问题描述】:

我有一个 5 行的文本区域。我只想显示一行,并且在焦点上应该显示剩余的 4 行。

【问题讨论】:

    标签: javascript jquery textarea jquery-events


    【解决方案1】:

    你可以试试这样的:

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

    moo 是你的文本区域。

    【讨论】:

      【解决方案2】:
      jQuery(function($){
        $('#foo').focus(function(){
          $(this).attr('rows',5);
        }).blur(function(){
          $(this).attr('rows',1);
        });
      });
      

      或者,使用更少的 jQuery,更少的输入,并获得更多的性能:

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

      【讨论】:

        【解决方案3】:

        试试这个

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

        【讨论】:

        猜你喜欢
        • 2012-07-05
        • 2020-01-22
        • 1970-01-01
        • 2021-01-02
        • 2021-08-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多