我写了一个过滤器,现在我有一个隐藏数字值的问题,这是过滤器html的代码:
<div class="height" th:classappend="${model.height}">some information</div>
<div class="searchColor" id="filterHeight">
<div class="searchTextColor"> Height:</div>
<input type="checkbox" id="27" value="2.7-2.9m" />2,7-2,9m<br/>
<input type="checkbox" id="29" value="2.9-3.0m"/>2,9-3,0m<br/>
<input type="checkbox" id="30" value="3.0-3.15m"/>3,0-3,15m<br/>
<input type="checkbox" id="315" value="3.15m"/>>3,15m
</div>
我写了这个筛选器,如果class
是字符串,这个筛选器可以工作,但我不明白为什么如果数字+字符串它不工作?
$("div[class='searchColor'] input").change(function () {
if($("#filterHeight input:checked").length > 0){
$('.height').show();
$("#filterHeight input:not(:checked)").each(function() {
var selectedStr = $(this).val();
$('.height' + selectedStr).hide();
});
我需要if
,因为我使用了几个条件
发布于 2017-02-10 12:33:48
我相信你的问题是复选框输入中的值有句点'.',这会被jQuery解释为类分隔符。
因此,对于您的线路:
$('.height' + selectedStr).hide();
可能会像这样被执行:
$('.height2.7-2.9m').hide();
但是jQuery会查看该字符串并用句点将其拆分,所以它不会查找“.height2.7-2.9m”类的元素,而是查找所有类都是“.height2”、“.7-2”和“.9m”的元素。
尝试从复选框值名称(以及您试图在HTML中匹配的类)中删除点
https://stackoverflow.com/questions/42151524
复制相似问题