在EXTJs中创建一个按钮

时间:2013-10-04 10:52:23

标签: button extjs4

我有一个登录界面,其中有一个ExtJs表单面板,其中包含两个按钮Login和Reset。 现在,我正在尝试在lofin面板下方添加另一个按钮,以便为新用户注册。 但按钮出现在屏幕的底部,出现滚动条使页面看起来很难看!

我在login.jsp文件中有这些:

<link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all-access.css">   
<script type="text/javascript" src="extjs/ext-all.js"></script>
<script type="text/javascript" src="js/app.js"></script>    

这是我的app.js文件:

Ext.onReady(function(){
    Ext.QuickTips.init();
    var login = new Ext.FormPanel({
        labelWidth:100,
        frame:true,
        title:'Member Login',
        defaultType:'textfield',
        monitorValid:true,

        // Specific attributes for the text fields for username / password. 
        // The "name" attribute defines the name of variables sent to the server.
        items:[{
            fieldLabel:'Username',
            name:'loginUsername',
            allowBlank:false
        },{
            fieldLabel:'Password',
            name:'loginPassword',
            inputType:'password',
            allowBlank:false
        }],

        buttons: [{    
            text: 'New User Register',
            scale: 'medium',
            handler: function()
            {        
                login.getForm().doAction('standardsubmit',{
                    target : '_self',
                    method : 'POST',
                    standardSubmit:true,
                    formBind: false,
                    url: 'registration.jsp'
                })
            }
        },{
            text: 'Login',
            scale: 'medium',
            handler: function()
            {
                login.getForm().doAction('standardsubmit',{
                    target : '_self',
                    method : 'POST',
                    standardSubmit:true,
                    formBind: true,
                    url: 'index.jsp'
                })
            }
        },{
            text: 'Reset',
            scale: 'medium',
            handler: function(){
                login.getForm().reset();
            }
        }]
    });

    // This just creates a window to wrap the login form. 
    // The login object is passed to the items collection.       
    var win = new Ext.Window({
        layout:'fit',
        width:325,
        height:175,
        closable: false,
        resizable: false,
        plain: true,
        border: false,    

        items: [login]
    });
    win.show();    
});

我尝试使用上面结尾的Ext.Create添加一个新按钮,但它不起作用。 我尝试将代码放在一个单独的js文件中,并将带有src的脚本标记与单独的脚本标记中的面板文件一起添加到按钮文件中,甚至失败。

有人可以帮我创建一个单独的按钮和我想要的位置吗? 任何形式的帮助表示赞赏。感谢。

我到处寻找,我尽我所能,但我无法想出答案。

注意:代码使问题看起来很长很长,但我的主要问题是问题的顶部和底部。

1 个答案:

答案 0 :(得分:0)

我假设您不想在登录面板中添加新按钮,否则您无论如何都可以在按钮列表中添加另一个按钮。要在登录面板下添加按钮并在窗口内按YET,请执行以下步骤;

  1. 将表单面板作为项目放在容器中

  2. 在表单面板

  3. 后,将您的按钮添加为容器中的第二项
  4. 将窗格中的面板添加到窗口

  5. Voilah!你也可以尝试给你的窗口和'id',例如'id=loginWindow',然后调用代码

    Ext.getCmp('loginWindow').add(
        {
         xtype:button,
         text:'Yay!'
         }
    );
    

    如果您需要更多针对特定代码的帮助,请随时给我留言。我知道你的感觉兄弟&lt; 3