解决extjs 单选及其传值的问题

一种是form里面直接提交传值给后台的例子:
Ext.onReady(function(){
var formPanel = new Ext.FormPanel({
id : "formPanel",
name : "formPanel",
width : 800,
renderTo : "formPanelDiv",
onSubmit: Ext.emptyFn,
submit: function(){
this.getEl().dom.action="formPanel.htm";
this.getEl().dom.submit();
},
items : [
new Ext.form.TextField({
id : "id",
name : "id",
allowBlank : false,
blankText : "ID不能为空",
fieldLabel : "ID",
labelStyle : "text-align:right"
}),
new Ext.form.TextField({
id : "name",
name : "name",
allowBlank : false,
blankText : "姓名不能为空",
fieldLabel : "姓名",
labelStyle : "text-align:right"
}),
new Ext.form.RadioGroup({
fieldLabel : "性别",
labelStyle : "text-align:right",
width : 80,
items : [
new Ext.form.Radio({
name : "sex",
boxLabel : "男",
inputValue : "male",
width : 20
}),
new Ext.form.Radio({
name : "sex",
boxLabel : "女",
inputValue : "female",
width : 20
})
]
}),
new Ext.form.TextField({
id : "email",
name : "email",
fieldLabel : "邮箱",
labelStyle : "text-align:right"
})
],
buttons : [
{
text : "登录",
id : "btn_login",
handler : function(){
if(formPanel.getForm().isValid()){
formPanel.getForm().submit();
}
}
},
{
text : "重置",
id : "btn_reset",
handler : function(){
formPanel.getForm().reset();
}
}
],
buttonAlign : "center"
});
});


后台是controller或jsp可以直接接收form提交过来的值
String sex= request.getParameter("sex");
...........

第二种是用ajax传值的例子:

Ext.onReady(function(){  

Ext.QuickTips.init();

Ext.override(Ext.form.RadioGroup, {
getValue: function(){
var v;
if (this.rendered) {
this.items.each(function(item){
if (!item.getValue())
return true;
v = item.getRawValue();
return false;
});
}
else {
for (var k in this.items) {
if (this.items[k].checked) {
v = this.items[k].inputValue;
break;
}
}
}
return v;
},
setValue: function(v){
if (this.rendered)
this.items.each(function(item){
item.setValue(item.getRawValue() == v);
});
else {
for (var k in this.items) {
this.items[k].checked = this.items[k].inputValue == v;
}
}
}
});


var radiogroup= new Ext.form.RadioGroup({
fieldLabel : "radioGroup",
items : [{
boxLabel : '男',
inputValue : "男",
name : "rg",
checked : true
}, {
boxLabel : '女',
name : "rg",
inputValue : "女"
}]
});

var _form=new Ext.form.FormPanel({

renderTo:'login-form',

title:'系统登录',

frame:true,

width:290,

height:160,

layout:'form',

buttonAlign:'center',

labelAlign:'center',

defaults:{width:160,labelWidth:80,xtype:'textfield'},

items:[

{fieldLabel:'用 户 名',vtype:'alpha',id:'name',name:'name'},

{fieldLabel:'通 行 证',inputType:'password',vtype:'alpha',id:'pass',name:'pass'},

radiogroup

],

buttons:[

{
text:'登 录',
style:'margin-right:15',
handler : function(){
if(_form.getForm().isValid()){
Ext.Ajax.request({
method : "post",
url : "test2.jsp",
params : {
sex : radiogroup.getValue()
},
callback : function(options,success,response){
Ext.Msg.alert('提示',response.responseText);
}
});
}
}
},

{

text:'清 除',

style:'margin-left:15',

handler:function(){

var _name=_form.findById('name').setValue('');

var _pass=_form.findById('pass').setValue('');

}

}

]

});

});


在后台的controller或jsp,可以直接用
String sex = request.getParameter("sex");
接收传值。
不知道大家有没发现,有ajax与没有ajax,传值是有点区别的
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值