重写ext的TextField控件,增加鼠标悬浮提示和控件后加说明文字
2012-02-08 10:49
786 查看
在使用ext的过程中,有时需要在TextField后加上说明性文字和鼠标悬浮提示的需求,在网上找到相关资料在整合了下
Ext.override(Ext.form.TextField, {
followtext: {text:'',class:''}, //控件后说明内容,可以自己增加项
tooltip: {text:'',title:''}, //鼠标悬浮提示,可以自己增加项
onRender: function (ct, position) {
Ext.form.TextField.superclass.onRender.call(this, ct, position);
var followlength = 0; //字符占位长度px
if (this.followtext.text != '') {
this.followEl = ct.createChild({
tag: 'div',
html: this.followtext.text
});
if (this.followtext.class)
this.followEl.addClass(this.followtext.class);
else
this.followEl.addClass('x-form-follow');
followlength = this.followtext.text.replace(/[^\x00-\xff]/g, "xx").length * 6 + 2;
this.width = this.width - followlength;
this.alignErrorIcon = function () {
this.errorIcon.alignTo(this.followEl, 'tl-tr', [2, 0]);
};
}
//鼠标移到文本框上时提示
if (this.tooltip.text) {
new Ext.ToolTip({
target: this.id,
trackMouse: false,
draggable: true,
maxWidth: 200,
minWidth: 100,
title: this.tooltip.title,
html: this.tooltip.text
});
}
}
});
效果:
Ext.override(Ext.form.TextField, {
followtext: {text:'',class:''}, //控件后说明内容,可以自己增加项
tooltip: {text:'',title:''}, //鼠标悬浮提示,可以自己增加项
onRender: function (ct, position) {
Ext.form.TextField.superclass.onRender.call(this, ct, position);
var followlength = 0; //字符占位长度px
if (this.followtext.text != '') {
this.followEl = ct.createChild({
tag: 'div',
html: this.followtext.text
});
if (this.followtext.class)
this.followEl.addClass(this.followtext.class);
else
this.followEl.addClass('x-form-follow');
followlength = this.followtext.text.replace(/[^\x00-\xff]/g, "xx").length * 6 + 2;
this.width = this.width - followlength;
this.alignErrorIcon = function () {
this.errorIcon.alignTo(this.followEl, 'tl-tr', [2, 0]);
};
}
//鼠标移到文本框上时提示
if (this.tooltip.text) {
new Ext.ToolTip({
target: this.id,
trackMouse: false,
draggable: true,
maxWidth: 200,
minWidth: 100,
title: this.tooltip.title,
html: this.tooltip.text
});
}
}
});
效果:
相关文章推荐
- Ext.TextField自定义验证函数以及提示文字
- Extjs中如何在一行textfield后面增加文字提示
- 去掉Eclipses的鼠标悬浮提示和增加输代码提示
- Ext.Net/ExtJs:关于TextField控件内size、maxLength控制文本框输入字符长度属性失效问题分析以及解决方案
- MFC/VC中当鼠标停靠在按钮等控件上时出现文字提示功能
- Ext TextField默认提示信息,并支持中文按2个长度计算
- ExtJS -- QuickTip TextField鼠标移过提示内容
- MFC/VC中当鼠标经过按钮等控件时出现文字提示功能
- js文本框或者按钮鼠标悬停提示说明文字
- JS小功能,鼠标经过标签时悬浮层提示+点击可复制文字
- MFC/VC中当鼠标停靠在按钮等控件上时出现文字提示功能
- Extjs中textfield的悬浮提示
- MFC/VC中当鼠标停靠在按钮等控件上时出现文字提示功能
- qml中TextField实现添加文字的上限,同时添加文字时,提示文字消失。
- Extjs中textfield的悬浮提示
- 编辑控件的警告提示是:This text field does not specify an inputType or a hint
- 鼠标放到控件上 DIV悬浮提示效果(四种)
- VC中当鼠标停靠在按钮等控件上时出现文字提示功能
- MFC/VC中当鼠标停靠在按钮等控件上时出现文字提示功能
- 增加duilib edit控件的提示功能和多种文字颜色