简体   繁体   中英

Make .find non case sensitive

I can currently using:

$results.find('a[href$=".doc"]')

to find anything ending with .doc for editing reasons. However, this seems to be case sensitive, ie if a document ends with .DOC or .Doc, it will not find those. Is it possible to make this non case sensitive?

You have to create a function to match case insensitively.

$results.find('a').filter(function(){return /\.doc$/i.test(this.href);});

It is also possible to enumerate all 8 cases in the selector, but this won't scale easily.

$results.find('a[href$=".doc"],a[href$=".doC"],a[href$=".dOc"],a[href$=".dOC"],a[href$=".Doc"],a[href$=".DoC"],a[href$=".DOc"],a[href$=".DOC"]')

try this i am not sure :

$results.find("a:regex(href, /\.doc$/i)")

but this will work for all a tags so u can use it with $results somehow

$("a:regex(href, /\.doc$/i)")

http://api.jquery.com/category/selectors/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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