1

我正在处理一个多选框并发现

var count = dojo.query("option[selected ='selected']", dojo.byId('select_id')).length;

始终从页面(数据库)返回任何原始内容,但仍返回用户在运行时选择的内容。我在 Dojo 1.6 上运行。那么如何在运行时从多选框中计算所选选项的数量?

4

1 回答 1

1

我做了一个页面,显示用户和他们所在的组。这是一些代码。我不得不撕掉一些东西以使其简洁。最后一行代码回答了这个问题。它返回一个包含检查值的数组。

// Programattically create the select.
var _groups = new dojox.form.CheckedMultiSelect({
    multiple : true,
    class : "cssThing"
}, "groups" + _userNumber);

// Fill the CheckedMultiSelect boxes with unchecked data.
var tempArray = new Array();
dojo.forEach(groupList, function(row, index) {
    tempArray.push({
        value : row.value,
        label : row.label,
        selected : false,
    });
});
_groups.addOption(tempArray);

// Populate the CheckedMultiSelect with an array.
var tempArray = [];
dojo.forEach(user.groups, function(row) {
    tempArray.push(String(row.groupName));
});
_groups.set('value', tempArray);

// Get the CheckedMultiSelect values as an array.
_groups.get('value');
于 2013-04-05T03:16:31.323 回答