2012-08-14 129 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