当用户执行过滤操作时,我试图将代码这里应用到我的文档中,以隐藏不必要的rideshare-item div(而不是rideshare-detail)。我认为这取决于我针对div元素的方式,但我不确定。
谁能给我指出正确的方向吗?如何将小提琴中的元素指向文档
到目前为止,这是我的代码:
$('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();
}
});
}); 发布于 2015-05-01 01:08:28
我想你想要这样的东西:
$('#go-button').on('click', function(event) {
var startAddress = $('.start-address').val();
var destinationAddress = $('.end-address').val();
$('.panel').hide().filter(function(i) {
var waypoints = $(this).find('.waypoint');
var w_1 = waypoints.filter(":first").data('waypoint');
var w_2 = waypoints.filter(":last").data('waypoint');
return w_1 == startAddress && w_2 == destinationAddress;
}).show();
});演示
请注意,我将路径点的HTML从waypoint="..."更改为data-waypoint="..."。
https://stackoverflow.com/questions/29978720
复制相似问题