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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20947529/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 00:21:17  来源:igfitidea点击:

What does "a[href*=#]:not([href=#])" code mean?

htmlcsscss-selectors

提问by Tí Pro

I don't understand clearly what does this code mean ?

我不太明白这段代码是什么意思?

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

Thank you !

谢谢 !

回答by Luca Rainone

Simply:

简单地:

a[href*=#] 

gets all anchors (a) that contain#in href.

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

But with:

但与:

:not([href=#])

excludes anchors with href exactly equalto #.

不包括美女主播与HREF正好等于#

Example:

例子:

<a href="#step1">yes</a>
<a href="page.php#step2">yes</a>
<a href="#">no</a> 

the selector gets the first two anchors, but it excludes the last.

选择器获取前两个锚点,但排除最后一个。

回答by Baldráni

Just in case anyone had the same problem as me with it and new version of jQuery : The solution is not to use a[href*=#]:not([href=#])but

以防万一有人和我有同样的问题和新版本的 jQuery:解决方案不是使用a[href*=#]:not([href=#])而是

use

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

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

This was a breaking change in jQuery 2.2.4 onwards.

这是 jQuery 2.2.4 之后的一个重大变化。

回答by Sajad Karuthedath

means that all elements with href attribute conatining '#', exceptthose whose href attribute equals to #

意味着所有具有 href 属性的元素'#'except其 href 属性等于#

回答by moonwave99

That's a CSS3 selectorthat gets all the awhose hrefattribute containsa #, but are not just made up of the single #char.

这是一个 CSS3 选择器,它获取ahref属性包含a 的所有#元素,但不仅仅是由单个#字符组成。

e.g.

例如

Matched

匹配

<a href="#home">Home</a>
<a href="index.html#contact">Contact</a>

Not Matched

不匹配

<a href="#">Top</a>

回答by BenM

It is a CSS selector that matches any aelement that has a hrefattribute containing the #character, but not anchor tags which have only #.

它是一个 CSS 选择器,它匹配任何a具有href包含#字符的属性的元素,但不匹配只有#.

So for example, it'll match: <a href="#test">Test Anchor</a>, but not <a href="#">Blank</a>

例如,它会匹配: <a href="#test">Test Anchor</a>,但不匹配<a href="#">Blank</a>