【发布时间】:2021-10-15 17:16:27
【问题描述】:
我需要根据之前下拉菜单中的选择填充图像复选框选择,如下所示:
<div>Select the Brand:
<select id="ParentBrand"><option></option><option value="Brand1">Brand1</option><option value="Brand2">Brand2</option></select>
</div>
<div>Select the Parameter:
<select id="Parameter"><option></option><option value="Parameter1">Parameter1</option><option value="Parameter2">Parameter2</option></select>
</div>
<div id=SubBrand style="display: none;">Select the SubBrand:
<ul>
<li id="SubBrand1" value="Brand1-Parameter1" style="display: none;">
<input type="checkbox"/>
<label for="SubBrand1"><img src="http://townandcountryremovals.com/wp-content/uploads/2013/10/firefox-logo-200x200.png" /></label>
</li>
<li id="SubBrand2" value="Brand1-Parameter2" style="display: none;">
<input type="checkbox"/>
<label for="SubBrand2"><img src="http://tech21info.com/admin/wp-content/uploads/2013/03/chrome-logo-200x200.png" /></label>
</li>
<li id="SubBrand3" value="Brand2-Parameter1" style="display: none;">
<input type="checkbox"/>
<label for="SubBrand3"><img src="http://www.thebusinessofsports.com/wp-content/uploads/2010/10/facebook-icon-200x200.png" /></label>
</li>
<li id="SubBrand4" value="Brand2-Parameter2" style="display: none;">
<input type="checkbox"/>
<label for="SubBrand4"><img src="http://www.thebusinessofsports.com/wp-content/uploads/2010/10/facebook-icon-200x200.png" /></label>
</li>
</ul>
</div>
我的 jQuery 删除 'style="display: none;"' 进行选择,相关的 'li' 如下:
$("#ParentBrand").on('change', function() {
var ParentBrandSelected = $('#ParentBrand').val();
$("#Parameter").on('change', function() {
ParameterSelected = $(this).val()
$("#SubBrand ul li").each(function(e) {
jQuery(this)
.filter(($(this).attr('value')).split("-").includes(ParentBrandSelected) && ($(this).attr('value')).split("-").includes(ParameterSelected))
.css('display', '')
})
$("#SubBrand").show();
});
});
但是,'.css('display', '')' 不起作用,相关的 'li' 仍然隐藏。我该如何完成这项工作?
在这里找到完整的工作代码:https://jsfiddle.net/mh34nfk1/
【问题讨论】: