|
//定義表單
var simple = new Ext.FormPanel({
labelWidth: 75,
baseCls: 'x-plain',
width: 150,
defaultType: 'textfield',//默認字段類型
//定義表單元素
items: [{
fieldLabel: '帳戶',
name: 'name',//元素名稱
//anchor:'95%',//也可用此定義自適應寬度
allowBlank:false,//不允許為空
blankText:'帳戶不能為空'//錯誤提示內容
},{
inputType:'password',
fieldLabel: '密碼',
//anchor:'95%',
name: 'pws',
allowBlank:false,
blankText:'密碼不能為空'
}
],
buttons: [{
text: '登陸',
type: 'submit',
//定義表單提交事件
handler:function(){
if(simple.form.isValid()){//驗證合法后使用加載進度條
Ext.MessageBox.show({
title: '請稍等',
msg: '正在加載...',
progressText: '',
width:300,
progress:true,
closable:false,
animEl: 'loding'
});
//控制進度速度
var f = function(v){
return function(){
var i = v/11;
Ext.MessageBox.updateProgress(i, '');
};
};
for(var i = 1; i < 13; i++){
setTimeout(f(i), i*150);
}
//提交到服務器操作
simple.form.doAction('submit',{
url:'check.ASP',//文件路徑
method:'post',//提交方法post或get
params:'',
//提交成功的回調函數
success:function(form,action){
if (action.result.msg=='ok') {
document.location='index.html';
} else {
Ext.Msg.alert('登陸錯誤',action.result.msg);
}
},
//提交失敗的回調函數
failure:function(){
Ext.Msg.alert('錯誤','服務器出現錯誤請稍后再試!');
}
});
}
}
},{
text: '取消',
handler:function(){simple.form.reset();}//重置表單
}]
});
//定義窗體
var win = new Ext.Window({
id:'win',
title:'用戶登陸',
layout:'fit', //之前提到的布局方式fit,自適應布局
width:300,
height:150,
plain:true,
bodyStyle:'padding:5px;',
maximizable:false,//禁止最大化
closeAction:'close',
closable:false,//禁止關閉
collapsible:true,//可折疊
plain: true,
buttonAlign:'center',
items:simple//將表單作為窗體元素嵌套布局
});
win.show();//顯示窗體
JavaScript技術:ext實現完整的登錄代碼,轉載需保留來源!
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。