2012-08-14 59 views
3

我的目標:允許jQuery插件的jQuery插件的內聯版本。用逗號控制textarea的尺寸

我的問題: textarea輸入比原始div大,導致滾動條顯示。

嘗試的解決方案:

$('.editableDescription').editable('http://jsfiddle.net/echo/jsonp/', { 

id: 'data[Chantier][id]', 
name: 'data[Chantier][Description]', 
type: 'textarea', 
height: $(".editableDescription").height() + "px", 
width: $(".editableDescription").width()+ "px", 
onblur: 'submit', 
tooltip: '' 

});​ 

我試圖把包裝div的大小與jQuery,但它仍然失敗!

的jsfiddle:jsFiddle

回答

5

首先,你需要從.longtext刪除height:250px;,否則Jeditable將它作爲默認高度<textarea>

然後我確定.longtext<textarea>具有相同的樣式,它們將嵌套在其中,如line-height, font-size, font-family

而且我認爲您的文檔中可能有多個.longtext,因此您需要將不同的heights應用於不同的<textarea>s。所以我改變了這一點:

$('.editableDescription').editable('http://jsfiddle.net/echo/jsonp/', 
{ 
     id  : 'data[Chantier][id]', 
     name  : 'data[Chantier][Description]', 
     type  : 'textarea', 
     height:($(".editableDescription").height()) + "px", 
     width: ($(".editableDescription").width()) + "px", 
     onblur: 'submit', 
     tooltip : '' 
}); 

這樣:

$('.editableDescription').each(function() 
{ 
    $(this).editable('http://jsfiddle.net/echo/jsonp/', 
    { 
     id:'data[Chantier][id]', 
     name:'data[Chantier][Description]', 
     type:'textarea', 

     height:$(this).height()+'px', 
     /* here it will take the height of the currently active .longtext */ 

     width:$(this).width()+'px', 
     onblur:'submit', 
     tooltip: '' 
    }); 
}); 

DEMO

而這基本上它。

+0

正是我想要做的。 – 2012-08-14 09:48:10

+0

你能否快速解釋它爲什麼有效? – 2012-08-14 09:51:29

+0

更新了我的答案。 :) – snuffn 2012-08-14 10:15:54

0

您可以嘗試的CSS overflow屬性設置爲隱藏

+0

它當然會抑制滾動條。但它不能解決尺寸問題。 – 2012-08-14 08:46:41