Javascript 如何获取复选框的值
如何获取复选框的值Javascript 如何获取复选框的值,javascript,extjs,Javascript,Extjs,如何获取复选框的值 var tb = new Ext.Toolbar(); tb.add({ xtype: 'checkbox', boxLabel: 'Expand Groups by Default', id: 'GetChkBoxValue', checked: true, handler: function() {
var tb = new Ext.Toolbar();
tb.add({
xtype: 'checkbox',
boxLabel: 'Expand Groups by Default',
id: 'GetChkBoxValue',
checked: true,
handler: function() {
alert(this.getValue())
}
});
是否有可能在tb之外获取复选框的值。我做过类似的操作,但它没有启动
Ext.getCmp('GetChkBoxValue').getValue();
请尝试以下代码,它应该可以工作:
new Ext.Window({
renderTo: Ext.getBody(),
width: 500,
height: 200,
title: 'test window',
items: [{
xtype: 'checkbox',
boxLabel: 'Expand Groups by Default',
id: 'chkid',
checked: true
}]
}).show()
Ext.getCmp('chkid').getValue()
然后使用复选框和getValue()获得其状态(选中或未选中)。快乐的ExtJS编码 以下是对我有效的方法:
var expandAllGroupsCheckbox = Ext.create(
{
xtype: 'checkbox',
boxLabel: 'Expand Groups by Default',
id: 'chkid',
checked: true,
afterRender: function() {
Ext.form.Checkbox.superclass.afterRender.call(this);
alert(this.getValue());// giving true
this.checkChanged();
},
checkChanged: function()
{
var checked = expandAllGroupsCheckbox.getValue();
gv.startCollapsed = !checked;
if ( gv.mainBody )
{
gv.toggleAllGroups( !checked );
}
},
listeners: {
check: {
fn: function(){expandAllGroupsCheckbox.checkChanged()}
}
}
});
然后:
tbar: [
expandAllGroupsCheckbox
,
{
xtype: 'tbbutton',
icon: '/images/icon_list_props.gif',
handler: function() {
ShowPreferencesPage();
}
}
],
仅此而已:
var cbox = Ext.getCmp('cboxId');
alert(cbox.checked);
发生了什么事?错误?您创建的代码应该可以工作。我能想到的唯一一件事是,您正在尝试在呈现工具栏之前调用getValue。由于您的复选框是按需创建的(通过传入cfg对象),Ext.getCmp在呈现元素之前不会找到该元素。是的,问题是它总是给我false,因为对象是实例化的,并且在呈现之前被调用。我想知道如何获取复选框的值??我可以访问网格面板中复选框的值,如下所示Ext.getCmp('chkid')。getValue()使用此值如果为真,我必须检查组,如果为假,我必须折叠组。有人能帮我展开和折叠网格面板中的组吗。