首先在FormPanel里添加图片预览区以及图片选择组件
/**
* 图片上传区
*/
this.imageUploadForm = new Ext.form.FormPanel({
region: 'east',
fileUpload: true,
width: 300,
split: true,
defaultType: 'textfield',
bodyStyle: 'align: center;',
defaults:{
hideLabel: true
},
items:[{
// labelSeparator: '',
id:'browseImage',
autoCreate:{
tag: 'input',
type: 'image',
src: Ext.BLANK_IMAGE_URL,
style:'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);'
name: 'imageBrowse'
}
},{
inputType: 'file',
id: 'imageUpload',
cls: 'upst'
}]
});
接下来添加选择完图片后的change事件
Global.img_reg=/\.([jJ][pP][gG]){1}$|\.([jJ][pP][eE][gG]){1}$|\.([gG][iI][fF]){1}$|\.([pP][nN][gG]){1}$|\.([bB][mM][pP]){1}$/
/**
* 浏览改变事件
* 只有当imageUploadForm render后Ext.get('imageUpload')才有效
*/
this.imageUploadForm.on('render',function(f){
this.imageUploadForm.form.findField('imageUpload').on('render',function(){
Ext.get('imageUpload').on('change',function(field,newValue,oldValue ){
var url = 'file:///'+Ext.get('imageUpload').dom.value;
if(Global.img_reg.test(url)){
if(Ext.isIE7){
var image = Ext.get('imageBrowse').dom;
image.src = Ext.BLANK_IMAGE_URL;//覆盖原来的图片
image.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src= url;
}else{
Ext.get('imageBrowse').dom.src = url;
}
}
},this);
},this);
},this);