ExtJs 图片上传

上传控件:   
var panel3 = new Ext.form.FormPanel({   
    labelAlign : 'left',   
         labelWidth:60,   
    border : false,   
    bodyStyle : 'padding:4px;',   
    frame : false,   
    url : '../ajaxdata/uploadFile.jsp',   
    autoHeight : true,   
    fileUpload : true,   
    items : [{   
        id : 'file',   
        autoScroll : false,   
        xtype : 'textfield'  
                  fieldLabel:'本地上传',   
        name : 'file',   
        hideLabel : true,   
        // inputType : 'file'//按照Ext默认的属性将inputType设为file时,始终响应不了onchange事件,结果就以autoCreate的方式,如下,因为这种方式相当于html里的input,所以也就响应得了啦!   
  
        autoCreate : {   
            tag : "input",   
            type : "file",   
            size : "20",   
            autocomplete : "off",   
            onChange : "browseImages(this.value);"  
        }   
    }]   
  
    ,   
    buttons : [{   
        text : '上传',   
        handler : function() {   
            panel3.getForm().submit({   
                // waitTitle : "请稍候",   
                waitMsg : "正在上传...",   
                success : function(form, action){},   
                failure : function(form, action) {   
                    Global.alert('上传图片失败!');   
                }   
            })   
        }   
    }]   
});   
  
/*   
* 编辑  
* @date 2008 July 10  
*/  
经过实践,还存在一种可以激发change事件的方法;   
首先说一下获取form里面的field的三种方法:   
1)Ext.getCmp('id');   
2)FormPanel.getForm().findField('id/name');   
3)Ext.get('id/name');  //前提是FormPanel在界面上显示出来了   
  
应用上面的第1和第2种方法得到的组件均触发不了change事件,只有第三种方法可以   
触发,前提是FormPanel要在界面上显示出来,所以需要触发show事件,然后在show   
事件里调用Ext.get('id/name'),由于FormPanel经常是放在Ext.Window里的,所   
以新的问题又来了:   
  1)调用FormPanel.on('show',fn);//当Window显示出来的时候,事件没有触发   
  2)调用FormPanel.getForm().on('show',fn);//情况同上   
  3)调用FormPanel.ownerCt.on('show',fn);//OK 一切搞定   
其中scope也是需要注意的一项!   
     
   如果再不行的话,可以先调用:   
      FormPanel.ownerCt.on('render',function(){   
          FormPanel.ownerCt.on('show',fn,this);   
      },this);  

你可能感兴趣的:(html,jsp,ext)