2015-06-04 126 views
0

以下是我的代碼中列出不同輸入字段的一些小技巧。描述是256個字符,我想那裏有2-3行而不是1,寬度約爲兩倍。我已經深入了bootstrap的CSS,只能找出如何移動輸入框本身,而不是擴展textarea。有誰知道如何在引導中的表單輸入字段中擴展textarea?Bootstrap輸入Textarea行大小

<div class="control-group <?php echo !empty($descriptionError)?'error':'';?>"> 
    <label class="control-label">Description</label> 
    <div class="controls"> 
     <input "name="description" type="text" placeholder="Description" value="<?php echo !empty($description)?$description:'';?>"> 
     <?php if (!empty($descriptionError)): ?> 
      <span class="help-inline"><?php echo $descriptionError;?></span> 
     <?php endif;?> 
    </div> 
</div> 

引導信息:

/*! 
* Bootstrap v2.3.2 
* 
* Copyright 2013 Twitter, Inc 
* Licensed under the Apache License v2.0 
* http://www.apache.org/licenses/LICENSE-2.0 
* 
* Designed and built with all the love in the world by @mdo and @fat. 
*/ 

使用textarea和改變行和列,或寬度不工作

+0

如何使用textarea而不是輸入框? – Geoffrey

+0

你會認爲這會很簡單,但我改變了這個無效 – Steven

+0

使用textarea並設置寬度;你可以用CSS來做到這一點,或者你可以通過textarea的[cols](http://www.w3schools.com/tags/att_textarea_cols.asp)元素來完成。 – Geoffrey

回答

0

你可以使用一些jQuery來調整頁面加載。 輸入更改爲一個文本,並檢查了以下小提琴......不是我的代碼...

http://jsfiddle.net/SpYk3/m8Qk9/

(function($) { 
$.fn.autogrow = function() { 
    return this.each(function() { 
     var textarea = this; 
     $.fn.autogrow.resize(textarea); 
     $(textarea).focus(function() { 
      textarea.interval = setInterval(function() { 
       $.fn.autogrow.resize(textarea); 
      }, 500); 
     }).blur(function() { 
      clearInterval(textarea.interval); 
     }); 
    }); 
}; 
$.fn.autogrow.resize = function(textarea) { 
    var lineHeight = parseInt($(textarea).css('line-height'), 10); 
    var lines = textarea.value.split('\n'); 
    var columns = textarea.cols; 
    var lineCount = 0; 
    $.each(lines, function() { 
     lineCount += Math.ceil(this.length/columns) || 1; 
    }); 
    var height = lineHeight * (lineCount + 1); 
    $(textarea).css('height', height); 
}; 

})(jQuery的);

$('#test')。autogrow();