我很努力地让一段代码工作,但我不是一个jquery的人,所以请耐心等待。如何从选择器中删除元素
I have an outer DIV ($scope)
。它包含各种输入。
我找到了每个输入类型的所有条目,并对它们进行过滤以获得具有值的条目。这些存储在$条目中。
$inputs contains all the inputs regardless of type or status.
我想要做的是remove $entries from $inputs
离开差异。
它不起作用,目前我没有收到任何反射的错误,所以没有什么可继续。
我的第一个想法是,jquery无法将一个列表中的元素与另一个列表中的元素进行匹配,因为它只保存了一个索引,而不是实际的对象。这可能是完全错误的(请参阅第1行)。无论哪种方式,我需要找到一种获取所有元素并将它们分成2位的方法 - 那些具有值和没有值的方法。
所有帮助表示赞赏。
function inputLoaded(isPostback) {
if (typeof Page_Validators !== "undefined") {
$scope = $(".active-step:first");
$inputs = $scope.find(inputs);
$cb = $scope.find(checkboxes).filter(":checked");
$rb = $scope.find(radios).filter(":checked");
$sb = $scope.find(selects).filter(function() { return $(this).val() !== "None"; });
$ta = $scope.find(textareas).filter(function() { return $(this).val(); });
$tb = $scope.find(textboxes).filter(function() { return $(this).val(); });
$entries = $cb.add($rb).add($sb).add($ta).add($tb);
// Do things with $entries here
// Get elements that have not got entries
$el = $inputs.remove($entries);
}
}
'$ inputs.filter(input =>!$ entries.contains(input))'? – gcampbell
@gcampbell - 当OP不使用它时为什么选择es6? – evolutionxbox
'$ input.not($ entries)'会更简单。 –