简体   繁体   English

jQuery选择器通配符不在哪里

[英]jQuery selectors wildcard where not

Trying to figure out how to apply a wildcard concept to something while applying where not. 试图弄清楚如何将通配符概念应用于某事物,而不应用于何处。

Right now I have $('.zm_name[rel!="'+keyed+'"]').parent().hide(); 现在我有$('.zm_name[rel!="'+keyed+'"]').parent().hide(); which will hide everything not exactly matching the keyed value I am looking for, this works fine. 它将隐藏所有与我要查找的键值不完全匹配的东西,这很好。 However it only works when the keyed value is exact. 但是,仅当键值正确时才起作用。 So I am looking to have it so its like keyed* but anything not equal to the beginning of the string hide. 因此,我希望将其像keyed*但不等于字符串hide的开头。

I tried $('.zm_name[rel^!="'+keyed+'"]').parent().hide(); 我试过$('.zm_name[rel^!="'+keyed+'"]').parent().hide(); but only get a syntax error, I browsed through the jquery selectors section of the api, and can't seem to find what I am looking for exactly. 但仅出现语法错误,我浏览了api的jquery选择器部分,但似乎找不到确切的查找内容。 So I am wondering is there any actual way of combining this method? 所以我想知道是否有任何实际的方法来组合这种方法?

Try this 尝试这个

$('.zm_name:not(.zm_name[rel^="'+keyed+'"])').parent().hide();

//OR //要么

$('.zm_name:not([rel^="'+keyed+'"])').parent().hide();​​​​​​​

DEMO DEMO

I usually stay away from very long selectors because they can be confusing and redundant. 我通常远离很长的选择器,因为它们会造成混乱和多余。 Try using the filter method: 尝试使用filter方法:

$('.zm_name').filter(function(){ 
  return !(new RegExp('^'+ keyed)).test(this.rel); 
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM