Javascript jQuery筛选器帮助

Javascript jQuery筛选器帮助,javascript,jquery,filter,return-value,Javascript,Jquery,Filter,Return Value,这个代码有什么问题 var objects = $(".validated").filter(function(){ return $(this).attr("name") == 'name'; }).filter(function (){ return $(this).val() == '';

这个代码有什么问题

var objects = $(".validated").filter(function(){
                                   return $(this).attr("name") == 'name';
                             }).filter(function (){
                                   return $(this).val() == '';
                             });

这真的让我很头疼:(

当函数返回false时,Filter将删除一个元素。因此,当遇到name=“name”且为空的元素时,您希望它返回false

var objects = $(".validated").filter(function(){
                                   // Will return false when name="name"
                                   return $(this).attr("name") != 'name';
                             }).filter(function (){
                                   // Will return false when the value is blank
                                   // Added trim to ensure that blank spaces
                                   // are interpreted as a blank value
                                   return $.trim($(this).val()) != '';
                             });
缩短的版本将是:

var objects = $(".validated").filter(function(){
                  // Will return false when name="name" or blank value
                  return $(this).attr("name") != 'name' && $.trim($(this).val()) != '';
              });

你想做什么?什么不起作用?怎么办?它不起作用。我假设你想过滤掉任何名称不等于“name”的元素过滤掉任何没有空值的元素?从你的另一个问题来看,我想你要找的是to还是一起过滤?我想过滤掉空值,也过滤掉名称属性为“name”的元素,所以“name”位-当对象的属性为“name”=“name”时,它会将对象添加到数组“objects”中吗d还删除了带有空值的元素我不敢相信这被接受了。它没有达到tarnfeld的要求…他想在name='name'和元素值为空时过滤掉。当函数返回false时,过滤器会删除元素。“如果函数返回false,那么元素将被删除-任何其他内容,元素将保留在匹配元素的结果集中。”-我不太清楚他是否真的想做你所暗示的事情。他自己的代码似乎试图完全保留我所做的那些元素。你是第一个使用“过滤掉”这个词的人“.tarnfeld可能被“out”理解为“filter them out==remove the others”,例如,为这些或类似项添加一个错误类
var objects = $(".validated").filter(function() {
    var ele = $(this);
    return ele.attr("name") == 'name' || ele.val() == '';
});