gpt4 book ai didi

javascript - 编辑单元格时如何在 YUI 中显示字符数?

转载 作者:行者123 更新时间:2023-11-30 18:51:38 30 4
gpt4 key购买 nike

在 YUI 数据表中,我想限制用户可以在其中一个单元格中键入的字符数。我知道如何使用格式化程序正确显示数量,但是否有一种简单的方法来更改编辑器框以显示“124/500”字符数限制?

最佳答案

您必须创建自定义 CellEditor 并覆盖 renderForm方法如下

(function() {
var Ylang = YAHOO.lang,
Ywidget = YAHOO.widget;

YAHOO.namespace("yoshi");

var yoshi = YAHOO.yoshi;

yoshi.CustomInputText = function(settings) {
yoshi.CustomInputText.superclass.constructor.call(this, settings);

this.initializer(settings);
}

YAHOO.extend(yoshi.CustomInputText, Ywidget.TextboxCellEditor, {
_LABEL_CLASS:"yoshi-label",
min:null,
max:null,
initializer:function(settings) {
this.min = (settings && settings.min) || null;
this.max = (settings && settings.max) || null;
},
renderForm:function() {
var pElement;
if(Ylang.isValue(this.min) || Ylang.isValue(this.max)) {
pElement = document.createElement("p");

var minLabel = "";
if(Ylang.isValue(this.min)) {
minLabel = "min[" + this.min + "]";
}

var maxLabel = "";
if(Ylang.isValue(this.max)) {
minLabel = "max[" + this.max + "]";
}

pElement.innerHTML = minLabel + maxLabel;
pElement.className = this._LABEL_CLASS;

this.getContainerEl().appendChild(pElement);
}

yoshi.CustomInputText.superclass.renderForm.call(this);
}
})
})();

注意我定义了一个特定的 _LABEL_CLASS,您可以在其中提供自定义 CSS 类

.yoshi-label {
/* Set up custom CSS right here */
}

现在创建列设置时

var yoshi = YAHOO.yoshi;

editor:new yoshi.CustomInputText({min:124,max:500});

关于javascript - 编辑单元格时如何在 YUI 中显示字符数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3685655/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com