主要参考了sugarcrm中的部分代码,json由后台代码生成
html:
<select id="select1"
οnchange="addVariables(document.getElementById('select2'),this.options[this.selectedIndex].value);">
</select>
<select id="select2"></select>
javascript:
function addVariables(the_select, the_module) {
the_select.options.length = 0;
for (var i = 0; i < field_defs[the_module].length; i++) {
var new_option = document.createElement('option');
new_option.value = field_defs[the_module][i].name;
new_option.text = field_defs[the_module][i].value;
the_select.options.add(new_option, i);
}
}
var selectabc = document.getElementById('select1');
selectabc.options.length = 0;
count = 0;
for (var i in field_defs) {
var optionNew = document.createElement('option');
optionNew.value = i;
optionNew.text = i;
//alert(i + count);
selectabc.options.add(optionNew, count++);
}
addVariables(document.getElementById('select2'), 'Contacts');
json(已经转换成javascript数组):
var field_defs = {
"Contacts": [{
"name": "a",
"value": "a"},
{
"name": "b",
"value": "b"}],
"Users": [{
"name": "c",
"value": "c"},
{
"name": "d",
"value": "d"}]
};
例子: http://download.csdn.net/detail/pipi7772/4234264