0
我试图将代码here应用于我的document,以便在用户执行过滤操作时隐藏不需要的rideshare-item
div(而不是rideshare-detail
)。我认为这取决于我如何针对div元素,但我不确定。jQuery元素定位问题
有人请指点我正确的方向吗?我如何将jsfiddle中的元素定位到我的document?
这是到目前为止我的代码:
$('body').on('click', '#go-button', function(event){
// Collect values
var startAddress = $('.start-address').val();
var destinationAddress = $('.end-address').val();
// Only show matching pickup address and waypoint
$('.rideshare-item').show();
$('.rideshare-detail .waypoint').each(function(a,b){
var waypoint = $(b).attr('waypoint');
// if found
if((waypoint == startAddress) || (waypoint == destinationAddress)){
return false;
}
// if not found
else if($((waypoint != startAddress) && (waypoint != destinationAddress)) && a == $('.rideshare-detail .waypoint').length-1) {
$(this).closest('.rideshare-item').hide();
}
});
});
你的问题是什么?并且...在'a == $('。rideshare-detail .waypoint')。length-1'中是'a'? – PeterKA
嗨@PeterKA,检查出这个问题的答案:http://stackoverflow.com/questions/29974852/hide-div-element-if-attribute-does-not-match-filter。我试图将代码应用到我自己的文档中。遇到集成问题 – methuselah