我想根据第一个下拉菜单的选择更改第二个下拉菜单,但目前无法正常工作。我使用bootstrap select的selectpicker和form-group类,但我不确定它是否会导致问题。根据第一个下拉菜单更改第二个下拉菜单
第二个下拉列表在第一个下拉列表被选中之前被禁用,并且只显示与数据组选择匹配的项目。
HTML:
<select id="seasons" class="selectpicker form-group" title="Choose season" onchange="filterSeason();">
<option value='2013-14'>2013-14</option>
<option value='2014-15'>2014-15</option>
<option value='2015-16'>2015-16</option>
<option value='2016-17'>2016-17</option>
</select>
<select id="clubs" class="selectpicker form-group" title="Choose club" disabled>
<optgroup data-group='2013-14' label="England">
<option data-group='2013-14' value='ENG1'>Team 1</option>
<option data-group='2013-14' value='ENG2'>Team 2</option>
</optgroup>
<optgroup data-group='2014-15' label="Spain">
<option data-group='2014-15' value='SPA1'>Team 3</option>
</optgroup>
<optgroup data-group='2015-15' label="Germany">
<option data-group='2015-16' value='GER1'>Team 4</option>
<option data-group='2015-16' value='GER2'>Team 5</option>
<option data-group='2015-16' value='GER3'>Team 6</option>
</optgroup>
</select>
的jQuery:
function filterSeason() {
var seasons = $("#seasons").find('option:selected').text();
$("#option-container").children().appendTo("#clubs");
var selectSeason = $("#clubs").children("[data-group!='"+seasons+"']");
selectSeason.appendTo("#option-container");
$("#clubs").removeAttr("disabled");
};
所以,你要只与数据组中的项目是selebtable ?请在您的问题中包含'#option-container'值 –
我认为: