选择没有 href 的锚点

发布于 2024-12-04 01:29:32 字数 195 浏览 4 评论 0原文

我想更改所有没有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

趁年轻赶紧闹 2024-12-11 01:29:32

您将需要此选择器(兼容 jQuery/CSS):

a:not([href])

如果您需要 IE 支持(因为 :not()),请将其用作 jQuery 选择器。否则,您可以将其用于 CSS 规则。

You'll want this selector (jQuery/CSS compatible):

a:not([href])

If you need IE support (because of that :not()), use it as a jQuery selector. Otherwise, you can use it for a CSS rule.

李白 2024-12-11 01:29:32

使用 $("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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文