用ExtJs制作登陆界面
第一步引入ExtJs文件及相关js文件:
<script src=”extjs/adapter/ext/ext-base.js” type=”text/javascript”></script> <script src=”extjs/ext-all-debug.js” type=”text/javascript”></script>
<script src=”extjs/ext-lang-zh_CN.js” type=”text/javascript”></script> <script src=”javascript/CheckCode.js” type=”text/javascript”></script>
<script src=”javascript/FullScreen.js” type=”text/javascript”></script> <script src=”javascript/Login.js” type=”text/javascript”></script>
第二步,登陆界面:
<body>
<div id=’loginpanel’ ></div>
</body>
第三步,登陆的js文件Login.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | Ext.BLANK_IMAGE_URL = 'pic/blank.gif';
var login = function() {
Ext.QuickTips.init();
Ext.lib.Ajax.defaultPostHeader += ";charset=utf-8";
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
// 实现具体的功能
var form = new Ext.FormPanel( {
defaultType : 'textfield',
labelWidth : 60,
style : 'background:#ffffff;padding:25px 35px 30px 16px;',
region : "center",
defaults : {
border : false,
allowBlank : false,
msgTarget : 'side',
blankText : '该字段不允许为空'
},
waitMsgTarget : true,
items : [
{
fieldLabel : '登录帐号',
name : 'user',
regex:/^[0-9a-zA-Z]{2,6}$/,
regexText:'只能为两到六位的大小写字母。'
},
{
fieldLabel : '登录密码',
name : 'pass',
inputType : 'password',
regex:/^.{4,}$/,
regexText:'长度不能少于4位'
},
{
xtype : 'panel',
layout : 'column',
items : [
{
width : 130,
layout : 'form',
border : false,
items : [{
fieldLabel : '效 验 码',
name : 'checkcode',
xtype : 'textfield',
allowBlank : false,
msgTarget : 'side',
blankText : '该字段不允许为空',
anchor : '98%'
}]
},
{ xtype : 'checkCode',
src : 'IMG.action',
width : 60,
height : 20,
handler : true
}
]
}],
buttons : [ {
text : '登陆',
handler : function() {
form.getForm().submit( {
success : function(f, a) {
OpenFullWin(a.result.url);
},
url : 'login.jsp',
waitMsg : '正在提交,请稍等...'
});
}
}, {
text : '取消',
handler : function() {
form.getForm().reset();
}
}]
});
var panel = new Ext.Panel( {
renderTo : 'loginpanel',
layout : "border",
width : 525,
height : 290,
defaults : {
border : false
},
items : [ {
region : "north",
height : 56,
html : 'pic'
}, {
region : "south",
height : 56,
html : 'pic'
}, {
region : "west",
width : 253,
html : 'pic'
}, form]
});
Ext.get('loginpanel').setStyle('position', 'absolute')
.center(Ext.getBody());
};
Ext.onReady(login); |
整体思路是:将登陆界面放入一个border布局的panel里面,该panel的各个部分border设为false。由于没有对
设置CSS,所以显示的登陆界面是在页面的左上角,故需要对panel设置css样式:
Ext.get(‘loginpanel’).setStyle(‘position’, ‘absolute’).center(Ext.getBody());
在CheckCode.js扩展了一个验证组件,代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | Ext.ux.form.CheckCode = Ext.extend(Ext.BoxComponent, {
initComponent : function() {
Ext.ux.form.CheckCode.superclass.initComponent.call(this);
this.addEvents('click');//初始化时间中注册click事件
},
onRender : function(ct, position) {
// 如果当前组件的dom不存在,则创建一个img对象
if (!this.el) {
this.el = document.createElement('img');
this.el.src = this.src;
if (this.forId) {
this.el.setAttribute('htmlFor', this.forId);
}
}
//类的onRender调用本类的onRender方法,也就是覆盖父类的onRender方法
Ext.form.Label.superclass.onRender.call(this, ct, position);
},
afterRender : function() {
Ext.ux.form.CheckCode.superclass.afterRender.call(this);
this.el.on("click", this.onClick, this);
},
onClick : function() {
if (this.handler === true)
this.el.dom.src = this.src + '?date=' + new Date();
else if (Ext.type(this.handler) == 'function')
this.handler(this);
this.fireEvent("click", this);
}
});
Ext.reg('checkCode', Ext.ux.form.CheckCode); |
本文章中的代码下载:http://d.namipan.com/d/ecb1aa65111e17620d18f0565b6f2d190f13bf3d55a62b00

这个验证码控件挺好的。不过我们公司做的登录不用ext,头说不够大气,晕~~~
我就是觉得这个控件很好,所以才把他贴出来了