52,780
社区成员
发帖
与我相关
我的任务
分享
//创建注册页面
var win;
Ext.onReady(function() {
Ext.BLANK_IMAGE_URL = 'ExtJs/resources/images/default/s.gif'; //替换默认的空白图片
Ext.QuickTips.init(); // 初始化鼠标停留时的显示框,这里用不上
Ext.form.Field.prototype.msgTarget = 'under';
// 点击登录时触发的事件
onClickReg = function() {
var regUrl = 'Register.aspx'; // 登录请求的url
// 这里Reg的Panel分为两部分,logoPanel和formPanel
// 创建logoPanel对象
var logoPanel = new Ext.Panel( {
baseCls : 'x-plain',
html : '填写注册信息'
});
// 创建formPanel对象
var formPanel = new Ext.form.FormPanel( {
bodyStyle : 'padding:35px 25px 0',
baseCls : 'x-plain',
defaults : {
width : 200
},
defaultType : 'textfield',
frame : true,
waitMsgTarget: true,
id : 'reg_form',
// form面板上的组件
items : [ {
fieldLabel : '用户名',
name : 'name',
id:'name',
blankText:'注册用户名不能为空',
regex : /^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){5,11}$/,
regexText : '用户名不合法(必须以字母开头,长度6-12位)!',
emptyText : '填写用户名',
invalidText : '用户名已经被注册!',
validationEvent : 'blur',
validator :ValidUserName,
allowBlank:false
}, {
fieldLabel : '密 码',
inputType : 'password',
id:'password',
name : 'password',
emptyText : '填写登录密码',
blankText:'密码不能为空',
allowBlank:false
},{
fieldLabel : '确认密码',
id:'confpwd',
name : 'confpwd',
vtype : 'password',
inputType : 'password',
emptyText : '填写确认密码',
initialPassField : 'password',
blankText:'确认密码不能为空',
allowBlank:false
},{
fieldLabel : '邮 箱',
id:'mail',
name : 'mail',
emptyText : '请输入E-mail(电子邮箱)',
blankText:'E-mail(电子邮箱)不能为空',
regex : /^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,4}$/,
regexText : '电子邮件格式错误!',//验证错误之后的提示信息
allowBlank:false
},{
fieldLabel : '电 话',
id:'telephone',
name : 'telephone',
regex : /^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/,
regexText : '电话号码格式输入错误!'
},{
fieldLabel : '手 机',
id:'mobphone',
name : 'mobphone',
regex : /^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/,
regexText : '移动电话号码格式输入错误!'
},{
fieldLabel : 'QQ',
id:'QQ',
name : 'QQ'
}],
labelWidth : 80,
region : 'center',
url : regUrl
});
// 创建window对象,用来装置以上两个面板,使login显示在一个window上
win = new Ext.Window( {
modal: true,
// window上的按钮,按钮时独立的,也可以设置在formPanel里
buttons : [ {
handler : validatorData,//function() 按钮login触发的事件
scope : onClickReg,
text : '注册'
}, {
handler : function() { // 按钮cancel触发的事件
win.close();
},
scope : onClickReg,
text : '取消'
}],
buttonAlign : 'right',
closable : true,
draggable : true,
height : 400,
id : 'reg_win',
layout : 'border',
plain : true,
// window上的组件
items : [logoPanel, formPanel],
title : '用户注册',
width : 500
});
// 取得表单,参考login按钮触发的事件
form = formPanel.getForm();
// 显示window
win.show();
// return里的为onClickLogin的共有函数
return {
Success : function(f, a) {
if (a && a.result) { //a表示action,a.result表示action返回的结果数据
win.destroy(true);
// setCookie
// set window.location
}
},
Fail : function(f, a) {
Ext.Msg.alert('登录失败');
}
};
};
// 设置login事件
Ext.get('bt_Register').on('click', onClickReg);
});
//验证用户名是否已经注册
function ValidUserName()
{
var res
var UserName = Ext.getCmp("name").getValue();
Ext.Ajax.request
({
url : 'Register.aspx?method=ConfUserName&userName='+UserName,
method : 'post',
success : function(response,options)
{
var res = Ext.util.JSON.decode(response.responseText);
if(res.success == true)
{
isok=true;
}
else
{
isok=false;
}
}
});
return isok;
}