主要代码如下: <script type="text/javascript">
Ext.onReady(function(){ Ext.create('Ext.form.Panel', {
bodyPadding: 10,
width : 300,
title : 'Pizza Order',
items: [
{
xtype : 'fieldcontainer',
fieldLabel : 'Toppings',
defaultType: 'checkboxfield',
items: [
{
boxLabel : 'Anchovies',
name : 'topping',
inputValue: '1',
id : 'checkbox1'
}, {
boxLabel : 'Artichoke Hearts',
name : 'topping',
inputValue: '2',
checked : true,
id : 'checkbox2'
}, {
boxLabel : 'Bacon',
name : 'topping',
inputValue: '3',
id : 'checkbox3'
}
]
}
],
renderTo: Ext.getBody()
}); var array1 = document.getElementsByName("topping");alert(array1);alert(array1.length);// 要实现类似这样的功能,这里无效
var array2 = Ext.query("*[name=topping]");alert(array2);alert(array2.length);//用query也无 效,array值为“”
});
</script> 再补充说明下,就是想通过复选框的name值topping来求其数组,这里我用了两种方式,都无效, document.getElementsByName("topping");是普通js中使用的,另一种是ext中使用的,我用了query,也无效,不知 道问题出在哪里了?
Ext.onReady(function(){ Ext.create('Ext.form.Panel', {
bodyPadding: 10,
width : 300,
title : 'Pizza Order',
items: [
{
xtype : 'fieldcontainer',
fieldLabel : 'Toppings',
defaultType: 'checkboxfield',
items: [
{
boxLabel : 'Anchovies',
name : 'topping',
inputValue: '1',
id : 'checkbox1'
}, {
boxLabel : 'Artichoke Hearts',
name : 'topping',
inputValue: '2',
checked : true,
id : 'checkbox2'
}, {
boxLabel : 'Bacon',
name : 'topping',
inputValue: '3',
id : 'checkbox3'
}
]
}
],
renderTo: Ext.getBody()
}); var array1 = document.getElementsByName("topping");alert(array1);alert(array1.length);// 要实现类似这样的功能,这里无效
var array2 = Ext.query("*[name=topping]");alert(array2);alert(array2.length);//用query也无 效,array值为“”
});
</script> 再补充说明下,就是想通过复选框的name值topping来求其数组,这里我用了两种方式,都无效, document.getElementsByName("topping");是普通js中使用的,另一种是ext中使用的,我用了query,也无效,不知 道问题出在哪里了?
alert(v);复制上看看什么反应
给你专门写了个方法 可以根据name拿到所有checkbox
function getCheckBoxByName(name) {
var arr = [];
Ext.form.CheckboxManager.getByName(name).each(function(cb) {
arr.push(cb)
});
alert(arr.length)
}
我感觉应该这样
xtype : 'checkboxgroup',
fieldLabel : 'Toppings',
// defaultType: 'checkboxfield',
items: [
]