我们必须想办法添加:
$(".editInPlace").attr("maxLength", 180);
某处。
所以我们必须找到一个“钩子”来设置这个属性到 textarea 弹出时。我试图在插件的文档中寻找这种钩子,但没有找到。
如果没有人找到更好的方法来解决您的问题,您可以直接更改库的源代码。
createEditorElement: function() {
if (-1 === $.inArray(this.settings.field_type, ['text', 'textarea', 'select']))
throw "Unknown field_type <fnord>, supported are 'text', 'textarea' and 'select'";
var editor = null;
if ("select" === this.settings.field_type)
editor = this.createSelectEditor();
else if ("text" === this.settings.field_type)
editor = $('<input type="text" ' + this.inputNameAndClass()
+ ' size="' + this.settings.text_size + '" />');
else if ("textarea" === this.settings.field_type)
editor = $('<textarea ' + this.inputNameAndClass()
+ ' rows="' + this.settings.textarea_rows + '" '
+ ' cols="' + this.settings.textarea_cols + '" />');
return editor;
},
在返回“编辑器”之前,添加如下内容:
if(this.settings.textarea_maxLength) {
editor.attr("maxLength", this.settings.textarea_maxLength);
}
然后你必须在实例化editInPlace时将“maxLength”属性设置为选项字段:
$("#editme1").editInPlace({
/* the options you had before */
textarea_maxLength: 180
});
但是好像有点棘手,我没有测试,也许你应该考虑直接问插件的开发者。
哎呀,我在发布之前没有刷新页面,抱歉。这与@pln
的解决方案基本相同