价格滑动过滤器-隐藏父属性元素
Price slidefilter - hide the attribute elements parent
我试图合并一个价格滑动过滤器,但现在它隐藏了带有价格数据属性的元素。我希望以父元素为目标并将其隐藏。如何使脚本在父级上工作,但仍使用子级的数据属性?
HTML:
<div class="itembox centerbox">
<div class="priceinfo col5" data-price="119">€119</div>
</div>
脚本:
function showProducts(minPrice, maxPrice) {
$(".priceinfo.col5").hide().filter(function() {
var price = parseInt($(this).data("price"), 10);
return price >= minPrice && price <= maxPrice;
}).show();
}
$(function() {
var options = {
range: true,
min: 0,
max: 500,
values: [50, 300],
slide: function(event, ui) {
var min = ui.values[0],
max = ui.values[1];
$("#amount").val("$" + min + " - $" + max);
showProducts(min, max);
}
}, min, max;
$("#slider-range").slider(options);
min = $("#slider-range").slider("values", 0);
max = $("#slider-range").slider("values", 1);
$("#amount").val("$" + min + " - $" + max);
showProducts(min, max);
});
您可以
function showProducts(minPrice, maxPrice) {
$('.itembox:has(.priceinfo.col5)').hide().filter(function() {
var price = parseInt($(this).find('.priceinfo.col5').data("price"), 10);
return price >= minPrice && price <= maxPrice;
}).show();
}
$(function() {
var options = {
range: true,
min: 0,
max: 500,
values: [50, 300],
slide: function(event, ui) {
var min = ui.values[0],
max = ui.values[1];
$("#amount").val("$" + min + " - $" + max);
showProducts(min, max);
}
},
min, max;
$("#slider-range").slider(options);
min = $("#slider-range").slider("values", 0);
max = $("#slider-range").slider("values", 1);
$("#amount").val("$" + min + " - $" + max);
showProducts(min, max);
});
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/redmond/jquery-ui.css" rel="stylesheet" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.js"></script>
<div class="itembox centerbox">
<div class="priceinfo col5" data-price="119">€119</div>
</div>
<div class="itembox centerbox">
<div class="priceinfo col5" data-price="100">€100</div>
</div>
<div class="itembox centerbox">
<div class="priceinfo col5" data-price="150">€150</div>
</div>
<div class="itembox centerbox">
<div class="priceinfo col5" data-price="200">€200</div>
</div>
<div id="slider-range"></div>
<br />
<input id="amount" readonly />
尝试此修改:
function showProducts(minPrice, maxPrice) {
// hide all parent divs of .priceinfo.col5 divs
// by hiding the parent you hide children as well
$(".priceinfo.col5").each(function() {
$(this).parent().hide()
});
// show the parent of every data-price item that passes the filter test
$(".priceinfo.col5").filter(function() {
var price = parseInt($(this).data("price"), 10);
return price >= minPrice && price <= maxPrice;
}).each(function() {
$(this).parent.show()
});
}
相关文章:
- 如何从django表单库中隐藏复选框,并使用Javascript切换其显示属性
- 如何在弹出窗口中隐藏文本属性'It’传单上没有填写
- 正在代码隐藏中检索选定ListBox项的属性数据
- 为什么我的html节点保持类ng隐藏属性ng show=true
- 如何从浏览器隐藏视频src属性's检查元素
- 在Chrome中隐藏__proto__属性's控制台
- 隐藏元素:Javascript属性和CSS样式之间的区别
- 添加隐藏属性以存储其他属性值
- 使用jQuery隐藏具有非唯一属性的元素
- 如何使用 javascript 更改按钮的可见/隐藏属性
- 打印对象的所有隐藏属性
- jQuery-UI不能识别html5的隐藏属性
- 在返回字符串的getter上有一个隐藏属性
- Jquery显示隐藏属性
- 引导模式显示不会移除隐藏属性
- 我们如何从对象中获得隐藏属性
- Jquery通过隐藏属性和值比较改变span值
- ng-repeat隐藏属性,如果它等于DateTime.MinValue
- 在 Angular 智能表中过滤,如何使其不搜索隐藏属性
- 在 JavaScript 中使用重排隐藏元素,它与 CSS 隐藏属性有何不同