<转>Extjs中的提示信息用法

ExtJS.form中msgTarget

Ext表单提示方式:msgTarget:有4中方式:qtip,title,under,side

Ext.onReady(function(){
Ext.BLANK_IMAGE_URL="resources/images/default/s.gif";
Ext.QuickTips.init();// 初始化显示提示信息。没有它提示信息出不来。
Ext.form.Field.prototype.msgTarget = "side";


var form = new Ext.form.FormPanel({
title:"提示信息(side)",
height:200,
width:300,
frame:true,
labelSeparator:":",
labelWidth:60,
labelAlign:"right",
items:[
new Ext.form.TextField({
fieldLabel : "姓名",
allowBlank:false,
blankText:"请输入名字",
msgTarget:"qtip" //修改这里的值msgTarget:"title" msgTarget:"under" msgTarget:"side"
}),
new Ext.form.NumberField({
fieldLabel:"年龄",
allowBlank:false,
blankText:"请写年龄",
msgTarget:"qtip"
})
]
});
new Ext.Viewport({
title:"",
items:[form]
});
});

如图:

[img]http://dl.iteye.com/upload/attachment/0066/7603/1e03b478-93ed-3128-878d-9887d9ae18c5.jpg[/img]


[img]http://dl.iteye.com/upload/attachment/0066/7605/33aab4bc-8fb1-3dc0-a7dc-e6f0f5abdffb.jpg[/img]

[img]http://dl.iteye.com/upload/attachment/0066/7607/b06a8e45-830d-3430-a9f5-255d44da1c41.jpg[/img]

[img]http://dl.iteye.com/upload/attachment/0066/7609/d92a5452-e417-31df-a8c3-a572a6b9f3dd.jpg[/img]

使用under时要注意表单的高度,高度不够的话就会出现以下情况:
图:

[img]http://dl.iteye.com/upload/attachment/0066/7611/221be358-4a39-3867-b970-31d19afa9953.jpg[/img]
使用side是要注意表单的宽度,宽度不够就会出现以下情况:
图:

[img]http://dl.iteye.com/upload/attachment/0066/7613/7ebb3371-8cd2-3bf1-865b-bc5587f30bbe.jpg[/img]
在每个字段上加提示方式很烦琐,
只要在Ext.QuickTips.init();下加一行Ext.form.Field.prototype.msgTarget = "under";//title,qtip,side
就可以实现统一的提示方式了。

***********************************************************
※Ext.form.TextField※
Ext.onReady(function(){
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget="side";
var form = new Ext.form.FormPanel({
title:"Ext.form.FormPanel例子",
labelSeparator:":",
labelWidth:60,
bodyStyle:"padding:5 5 5 5",
frame:true,
height:120,
width:250,
items:[
new Ext.form.TextField({
fieldLabel:"用户名",
id:"userName",
selectOnFocus:true, //得到焦点时自动选择文本
allowBlank:false,
regex:/^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,4}$/,
regexText:"用户名格式错误"
}),
new Ext.form.TextField({
fieldLabel:"密码",
inputType:"password",
allowBlank:false
})
]
});
new Ext.Viewport({
title:"",
items:[form]
});
});

这里验证用户名必须是email格式的。先验证是否为空,然后在验证格式。


[img]http://dl.iteye.com/upload/attachment/0066/7615/6edbafeb-aec4-311a-8ef0-ae0f27f078f5.jpg[/img]


***********************************************************
※Ext.form.TextArea※
Ext.onReady(function(){
Ext.QuickTips.init();
var form = new Ext.form.FormPanel({
title:"Ext.form.TextArea例子",
labelSeparator:":",
labelWidth:60,
bodyStyle:"padding:5 5 5 5",
frame:true,
height:150,
width:250,
items:[
new Ext.form.TextArea({
id:"memo",
width:150,
fieldLabel:"备注"
})
],
buttons:[{text:"确定",handler:showValue}]
});
function showValue(){
var memo = form.findById("memo"); //获得输入控件
alert(memo.getValue()); //取得空间值
};
new Ext.Viewport({
title:"",
items:[form]
});
});



[img]http://dl.iteye.com/upload/attachment/0066/7617/228b5958-e82e-3f16-aa28-5131ca34efcf.jpg[/img]

***********************************************************
※Ext.form.NumberField※
Ext.onReady(function(){
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget="side";
var form = new Ext.form.FormPanel({
title:"Ext.form.NumberField例子",
labelSeparator:":",
labelWidth:60,
bodyStyle:"padding:5 5 5 5",
frame:true,
height:150,
width:250,
items:[
new Ext.form.NumberField({
fieldLabel:"整数",
allowDecimals:false, //不允许输入小数
nanText:"请输入有效数字", //无效数字提示
allowNegative:false //不允许输入负数
}),
new Ext.form.NumberField({
fieldLabel:"小数",
decimalPrecision:2, //精确到小数点后2位
allowDecimals:true,
nanText:"请输入有效数字",
allowNegative:false
}),
new Ext.form.NumberField({
fieldLabel:"数字限制",
baseChars:"12345" // 输入数字范围
}),
new Ext.form.NumberField({
fieldLabel:"数值限制",
maxValue:100, //最大值
minValue:50 //最小值
})
]
});
new Ext.Viewport({
title:"",
items:[form]
});
});

decimalPrecision会四舍五入。当小数保留2位时,14.23545,焦点离开后会变成 14.24
[img]http://dl.iteye.com/upload/attachment/0066/7619/d30fee43-1622-3fa4-bf6f-670189ab6bfe.jpg[/img]


转载自:[url]http://blog.163.com/xiao_mege/blog/static/729427532011327104847120/[/url]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值