我正在尝试使用 Joomla ChronoForms 进行“双重”下拉,但是当我从第一个下拉列表中选择某些内容时,页面上出现了 Javascript 错误,这是我的代码:
<select id="recipe" name="recipe">
<optgroup label="test" id="ch_1">
<option value="blabla">something here</option>
<option value="blabla">something here</option>
</optgroup>
<optgroup label="test244" id="ch_2">
<option value="blabla">something here</option>
<option value="blabla">something here</option>
</optgroup>
<optgroup label="testtt" id="ch_3">
<option value="blabla">something here</option>
<option value="blabla">something here</option>
</optgroup>
<optgroup label="testt23521" id="ch_4">
<option value="blabla">something here</option>
<option value="blabla">something here</option>
</optgroup>
<optgroup label="teeesstt" id="ch_5">
<option value="blabla">something here</option>
<option value="blabla">something here</option>
</optgroup>
</select>
JS代码是:
window.addEvent('load', function() {
var num_groups = 5;
var groups = new Array;
for ( var i = 1; i <= num_groups; i++ ) {
groups[i] = $('ch_'+i);
$('ch_'+i).remove();
}
$('chapter').value = '';
$('chapter').addEvent('change', function() {
var group_no = $('chapter').value;
if ( !group_no ) {
return;
}
$('#recipe optgroup').each(function(el) {el.remove()});
$('recipe').appendChild(groups[group_no]);
});
});
我收到的 JS 错误是:TypeError: Cannot call method 'each' of null
你能帮我解决这个问题吗?谢谢