JS小練習(xí)代碼之二第1/2頁
更新時間:2008年10月12日 23:25:25 作者:
JS練習(xí)代碼
相關(guān)的源代碼如下:
1.beginFormPanel.js(作用:外層html文件中表單的展現(xiàn))
<script>
var beginFormPanel = Ext.extend(Ext.form.FormPanel,{
constructor:function()
{
beginFormPanel.superclass.constructor.call
(
this,
{
title:"myForm(絕不裸奔)",
width:418,
height:180,
frame:true,
labelWidth:45,
style:"margin-left:250px",
defaultType:"textfield",
defaults:{anchor:"95%"},
items:
[
{
fieldLabel:"姓名",
name:"name"
},
{
fieldLabel:"年齡",
name:"age"
},
{
fieldLabel:"性別",
name:"sex"
},
{
fieldLabel:"住址",
name:"addr"
}
],
buttons:
[
{
text:"添加"
},
{
text:"修改"
},
{
text:"刪除"
}
],
renderTo:Ext.getBody()
}
) ;
}
}) ;
</script>
2.beginPanel.js(作用:GridPanel與窗口以及窗口中FormPanel的實現(xiàn))
<script>
/**************************** FormPanel *****************************************************/
var myWindowForm = Ext.extend(Ext.form.FormPanel,{
constructor:function()
{
myWindowForm.superclass.constructor.call
(
this,
{
labelWidth:45,
defaultType:"textfield",
defaults:{anchor:"93%"},
style:"padding:5px",
baseCls:"x-plain",
items:
[
{
fieldLabel:"姓名",
name:"name",
allowBlank:false,
blankText:"姓名不能夠為空!"
},
{
fieldLabel:"年齡",
name:"age",
allowBlank:false,
vtype:"age",
blankText:"年齡不能夠為空!"
},
{
fieldLabel:"性別",
name:"sex",
allowBlank:false,
blankText:"性別不能夠為空!"
},
{
fieldLabel:"住址",
name:"addr",
allowBlank:false,
blankText:"住址不能夠為空!"
}
]
}
) ;
},
getValues:function()
{
if(this.getForm().isValid())
{
return new Ext.data.Record(this.getForm().getValues()) ;
}
else
{
throw error("表單驗證沒通過哦!") ;
}
},
setValues:function(record)
{
this.getForm().loadRecord(record) ;
},
reset:function()
{
this.getForm().reset() ;
}
}) ;
/******************************** Window ***********************************/
var myWindow = Ext.extend(Ext.Window,{
form:new myWindowForm(),
constructor:function()
{
myWindow.superclass.constructor.call
(
this,
{
title:"myWindow(絕不裸奔)",
width:300,
height:185,
frame:true,
plain:true,
modal:true,
items:this.form,
closable:false,//禁止關(guān)閉
collapsible:true,//可折疊
buttons:
[
{
text:"確定",
handler:this.onSubmitClick,
scope:this
},
{
text:"取消",
handler:this.onCancelClick,
scope:this
}
]
}
) ;
this.addEvents("submit") ;
},
close:function()
{
this.hide() ;
},
onSubmitClick:function()
{
/*
try
{
this.fireEvent("submit",this,this.form.getValues()) ;
}
catch (error)
{
Ext.Msg.alert("警告","請將需要填寫的信息填寫完整!") ;
}
*/
this.fireEvent("submit",this,this.form.getValues()) ;
this.close() ;
},
onCancelClick:function()
{
//上面不加scope屬性則提示this.form為空
this.form.reset() ;
this.close() ;
}
}) ;
1.beginFormPanel.js(作用:外層html文件中表單的展現(xiàn))
<script>
var beginFormPanel = Ext.extend(Ext.form.FormPanel,{
constructor:function()
{
beginFormPanel.superclass.constructor.call
(
this,
{
title:"myForm(絕不裸奔)",
width:418,
height:180,
frame:true,
labelWidth:45,
style:"margin-left:250px",
defaultType:"textfield",
defaults:{anchor:"95%"},
items:
[
{
fieldLabel:"姓名",
name:"name"
},
{
fieldLabel:"年齡",
name:"age"
},
{
fieldLabel:"性別",
name:"sex"
},
{
fieldLabel:"住址",
name:"addr"
}
],
buttons:
[
{
text:"添加"
},
{
text:"修改"
},
{
text:"刪除"
}
],
renderTo:Ext.getBody()
}
) ;
}
}) ;
</script>
2.beginPanel.js(作用:GridPanel與窗口以及窗口中FormPanel的實現(xiàn))
<script>
/**************************** FormPanel *****************************************************/
var myWindowForm = Ext.extend(Ext.form.FormPanel,{
constructor:function()
{
myWindowForm.superclass.constructor.call
(
this,
{
labelWidth:45,
defaultType:"textfield",
defaults:{anchor:"93%"},
style:"padding:5px",
baseCls:"x-plain",
items:
[
{
fieldLabel:"姓名",
name:"name",
allowBlank:false,
blankText:"姓名不能夠為空!"
},
{
fieldLabel:"年齡",
name:"age",
allowBlank:false,
vtype:"age",
blankText:"年齡不能夠為空!"
},
{
fieldLabel:"性別",
name:"sex",
allowBlank:false,
blankText:"性別不能夠為空!"
},
{
fieldLabel:"住址",
name:"addr",
allowBlank:false,
blankText:"住址不能夠為空!"
}
]
}
) ;
},
getValues:function()
{
if(this.getForm().isValid())
{
return new Ext.data.Record(this.getForm().getValues()) ;
}
else
{
throw error("表單驗證沒通過哦!") ;
}
},
setValues:function(record)
{
this.getForm().loadRecord(record) ;
},
reset:function()
{
this.getForm().reset() ;
}
}) ;
/******************************** Window ***********************************/
var myWindow = Ext.extend(Ext.Window,{
form:new myWindowForm(),
constructor:function()
{
myWindow.superclass.constructor.call
(
this,
{
title:"myWindow(絕不裸奔)",
width:300,
height:185,
frame:true,
plain:true,
modal:true,
items:this.form,
closable:false,//禁止關(guān)閉
collapsible:true,//可折疊
buttons:
[
{
text:"確定",
handler:this.onSubmitClick,
scope:this
},
{
text:"取消",
handler:this.onCancelClick,
scope:this
}
]
}
) ;
this.addEvents("submit") ;
},
close:function()
{
this.hide() ;
},
onSubmitClick:function()
{
/*
try
{
this.fireEvent("submit",this,this.form.getValues()) ;
}
catch (error)
{
Ext.Msg.alert("警告","請將需要填寫的信息填寫完整!") ;
}
*/
this.fireEvent("submit",this,this.form.getValues()) ;
this.close() ;
},
onCancelClick:function()
{
//上面不加scope屬性則提示this.form為空
this.form.reset() ;
this.close() ;
}
}) ;
相關(guān)文章
JavaScript實現(xiàn)JSON合并操作示例【遞歸深度合并】
這篇文章主要介紹了JavaScript實現(xiàn)JSON合并操作,結(jié)合實例形式分析了javascript基于遞歸深度實現(xiàn)json合并操作相關(guān)實現(xiàn)技巧與注意事項,需要的朋友可以參考下2018-09-09
JavaScript實現(xiàn)有限狀態(tài)機(jī)的示例代碼
有限狀態(tài)機(jī)(Finite?State?Machine,?FSM)是一種數(shù)學(xué)模型,用于描述系統(tǒng)在不同狀態(tài)下的行為,本文給大家介紹JavaScript實現(xiàn)有限狀態(tài)機(jī)的示例代碼,感興趣的朋友一起看看吧2024-12-12

