选择没有 href 的锚点
我想更改所有没有 href
属性的锚点的 css 样式。
我可以使用选择器来选择以 $('a[href^="some_link"]')
开头的锚点。但我希望反之亦然。如何使用 jquery 选择没有 href 的锚点?
另外,我可以使用 css 选择器来实现这一点吗?
谢谢。
I'd like to change the css style of all the anchors without href
attribute.
I can use selector to select anchors that start with something using $('a[href^="some_link"]')
. But I want it to be vice versa. How can I select anchors without href using jquery?
Also, can I achieve this using a css selector?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将需要此选择器(兼容 jQuery/CSS):
如果您需要 IE 支持(因为
:not()
),请将其用作 jQuery 选择器。否则,您可以将其用于 CSS 规则。You'll want this selector (jQuery/CSS compatible):
If you need IE support (because of that
:not()
), use it as a jQuery selector. Otherwise, you can use it for a CSS rule.使用
$("a").filter(function() { return !this.attributes['href']; })
。它有点长,但浏览器可以优化锚点的选择,并且比 Sizzle(或 querySelectorAll)运行更快地进行过滤。
http://jsfiddle.net/9PWQB/
Use
$("a").filter(function() { return !this.attributes['href']; })
.It's a little longer, but browsers can optimise the selection of the anchors, and do the filtering faster than Sizzle (or querySelectorAll) can run.
http://jsfiddle.net/9PWQB/