"a [href*=#]:not([href =#])"代码是什么意思?

Tí *_*Pro 21 html css css-selectors

我不清楚这段代码是什么意思?

a[href*=#]:not([href=#])
Run Code Online (Sandbox Code Playgroud)

谢谢 !

Luc*_*one 35

只是

a[href*=#] 
Run Code Online (Sandbox Code Playgroud)

获取a包含#在href中但包含的所有锚点():

:not([href=#])
Run Code Online (Sandbox Code Playgroud)

排除href exaclty等于的锚点 #

例:

<a href="#step1">yes</a>
<a href="page.php#step2">yes</a>
<a href="#">no</a> 
Run Code Online (Sandbox Code Playgroud)

选择器得到前两个锚,但它排除了最后一个.


Bal*_*áni 33

以防任何人遇到与我相同的问题和新版本的jQuery:解决方案是不使用a[href*=#]:not([href=#])但是

使用

a[href*="#"]:not([href="#"])

这是jQuery 2.2.4以后的一个重大变化.

  • ..或者像它一样逃避它:a [href*= \\#]:not([href = \\#]) (3认同)