Extjs NumberField后面加单位,UnitText

UnitText.js

=======================

// 输入框textfield后面放字unitText定义:
Ext.override(Ext.form.TextField, {
unitText : '',
onRender : function(ct, position) {
Ext.form.TextField.superclass.onRender.call(this, ct, position);

if (this.unitText != '') {
this.unitEl = ct.createChild({
tag : 'div',
html : this.unitText
});
this.unitEl.addClass('x-form-unit');
// 增加单位名称的同时按单位名称大小减少文本框的长度 初步考虑了中英文混排 未考虑为负的情况
this.width = this.width
- (this.unitText.replace(/[^\x00-\xff]/g, "xx").length * 6 + 2);
// 同时修改错误提示图标的位置
this.alignErrorIcon = function() {
this.errorIcon.alignTo(this.unitEl, 'tl-tr', [2, 0]);
};
}
}
});



将UnitText.js放入到jsp文件中,加上css样式,如下:

<style>
.x-form-unit {
height: 22px;
line-height: 22px;
padding-left: 2px;
display: inline-block;
display: inline;
}
</style>
<script type="text/javascript" src="UnitText.js"></script>



这样就可以用了,使用方法如下:

var jine = new Ext.form.NumberField({
id : 'je',
fieldLabel : '金额',
allowDecimals : true, // 允许小数点?
allowNegative : false, // 允许负数?
width : 100,
style : 'text-align:right',
unitText : ' 元'
});
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值