Extjs登陆

<body>    
    <table width="100%" border="0">
      <tr>
       <td>
        <div id="formdiv"></div>
       </td>
      </tr>
      <tr>
       <td>
        <div id="btndiv"></div>
       </td>
      </tr>
    </table>
</body>
</html>
<script language="javascript" type="text/javascript">
    Ext.onReady(function () {
        Ext.QuickTips.init();
        Ext.form.Field.prototype.msgTarget = 'side';
        function Onlogin() {
            if (simple.getForm().isValid()) {
                //Ext.get("logonname").dom.value = "";
                isValidUser(Ext.get("logonname").getValue(), Ext.get("Password").getValue());
            }
            else {
                alert("no");
            }
        };

        function isValidUser(strusername, strpassword) {
            Ext.Ajax.request({
                url: 'WebService.asmx/isValidUser',
                method: 'POST',
                jsonData: { username: strusername, password: strpassword },
                success: AlertResult,
                failure: On_Error
            });
        };
        function AlertResult(result) {
            var data = Ext.util.JSON.decode(result.responseText);
            if (result.responseText.indexOf('ok') != -1) {
                window.location = "DataGrid.aspx";
            }
            else {
                alert("no");
            }
        };

        function On_Error() {

        };

        var simple = new Ext.FormPanel({
            defaultType: 'textfield',
            labelAlign: 'right',
            title: 'form',
            labelWidth: 90,
            buttonAlign: 'center',
            frame: true,
            width: 220,
            items: [{ xtype: 'textfield', fieldLabel: 'User Name', allowBlank: false, blankText: '请输入用户名', id: 'logonname' },
                    { xtype: 'textfield', fieldLabel: 'Password', allowBlank: false, inputType: 'password', id: 'Password', enableKeyEvents: true}],
            buttons: [{ text: "确定", handler: Onlogin }, { text: "重置", handler: function () { simple.form.reset(); } }],
            keys: [{ key: Ext.EventObject.ENTER, fn: Onlogin, scope: this}]
        });
        simple.render("formdiv");


        var searchKey = new Ext.form.TextField({
            id: 'searchkey',
            fieldLabel: 'text',
            name: 'text',
            defaultType: 'textfield',
            enableKeyEvents: true,
            blankText: "这个字段最好不要为空"
        });
        searchKey.render("btndiv");
        searchKey.on('keypress', function () {
            alert(event.keyCode);
        });

    });

</script>

posted @ 2011-03-22 12:28  Seven_Milk  阅读(714)  评论(0编辑  收藏  举报