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
What does "a[href*=#]:not([href=#])" code mean?
提问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 '#'
, except
those whose href attribute equals to #
意味着所有具有 href 属性的元素'#'
,except
其 href 属性等于#
回答by moonwave99
That's a CSS3 selectorthat gets all the a
whose href
attribute containsa #
, but are not just made up of the single #
char.
这是一个 CSS3 选择器,它获取a
其href
属性包含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 a
element that has a href
attribute 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>