如何将filter()函数的输出存储在数组或字符串中,以便以后在另一个函数中使用?
jQuery('.marca').change(function(){
var regex = new RegExp(/^2x\d$/);
if(jQuery(this).find('input').prop("checked")) {
jQuery(this).nextAll().filter(function() {
// I would like to save the output from this .filter
// function to use to make a string of classes to pass to the next function.
console.log(this.className.match(regex)); //output below
return this.className.match(regex);
})
.show();
} else {
jQuery(this).nextAll().hide();
}
});
我使用上面的代码检查带有复选框的表单的类,并且仅当选中了上一个按钮时才显示“子类”。
我使用regex和filter()来查找和显示下一组类,并希望将生成的类传递到下一个jQuery选择器中,以避免手动添加它们。
https://jsfiddle.net/srjjj/brtp8x2h/9/
我试图简单地将结果添加到变量中,但它不会存储整个值集,而只存储最后一个值(.2x4)。
console.log output