链接
http://domain.com/[random]/#foo
http://domain.com/[random]/bar
如何选择以 http://domain.com/ 开头的链接然后是通配符([随机]),然后是 #?
最佳答案
你可以这样做:
$('a[href^="http://domain.com/"][href$="#foo"]');
选择具有 href
的 a
元素,该 href
以 http://domain.com/
开头并以 #foo 结尾
。
如果您不关心 foo
部分而只关心哈希值,请使用以下代码:
$('a[href^="http://domain.com/"][href*="#"]');
选择的第二部分是“包含”过滤器。
关于字符串中的 jQuery 选择器通配符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17634482/