extjs怎么让文本框的光标默认显示在用户名

2025-06-23 22:52:58
推荐回答(1个)
回答1:


 
  
  
  
   
     
 Ext.onReady(function(){
 var panel=new Ext.form.FormPanel({
    layout:"absolute",
    items:[{
     x:10,y:15,
     xtype : "label",
     text : "用户名:"
    },{
     x:90,y:11,
     xtype : "textfield",
     id:'name',
     width:200
    },{
     xtype : "button",
     x : 140,
     y : 40,
     width : 60,
     text : " 确  定 ",
     handler : function(){
     
     }
    }]
   });
   var win=new Ext.Window({
    title:'登录',
    width:340,
    height:110,
    layout:"fit",
    plain:true,
    modal : true,
    closeAction:"hide",    
    items:[panel]
   });
 
  win.show();
  Ext.getCmp('name').focus(false, 100); //这里是让文本框获取焦点的方法,因为组件渲染需要时间,所以加个延迟就行了
  
});
 
 
 
 

 

简单给你写了个例子,有问题在问我吧~