使用 javascript 和/或 jQuery,我如何测试/匹配一个对象及其所有兄弟姐妹?我不是程序员,所以请放轻松。提前致谢。:)
// Make an array of the checked inputs
var aInputs = $('.listings-inputs input:checked').toArray();
// Turn that array into a new array made from each items value.
var aValues = $.map(aInputs, function(i){
return $(i).val();
});
// Create new variable, set the value to the joined array set to lower case.
// Use this variable as the string to test
var sValues = aValues.join(' ').toLowerCase();
$.each(sSplitTags, function(i){
var re = new RegExp(sSplitTags[i],'i');
// this test works, but not for the siblings
if(re.test(sValues)){
// This line does not work, but it is the gist of the question
// if( (re.test(sValues)) && ($(re).siblings().test(sValues))){
alert('match');
}
else{
alert('no match');
}
});
/*
// Begin: There is a more elegant way to do this...
// Create new Regular Expressions
var re0 = new RegExp(sSplitTags[0],'i');
var re1 = new RegExp(sSplitTags[1],'i');
// if(thisInput.attr('value') == $(this).text()){
if((re0.test(sValues)) && (re1.test(sValues))){
// End: There is a more elegant way to do this...
$(this).parent().show();
}
else{
$(this).parent().hide();
}
*/