jquery中如何通过href获取元素?
我想通过 jquery 或 javascript 中的 href 属性获取元素。这可能吗?
I want to get an element by its href attribute in jquery or javascript. Is that possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是的,您可以使用 jQuery 的 属性选择器 来实现。
或者,如果您感兴趣的是以某个 URL 开头的链接,请使用 attribute-starts-with 选择器:
Yes, you can use jQuery's attribute selector for that.
Alternatively, if your interest is rather links starting with a certain URL, use the attribute-starts-with selector:
如果您想获取 href 属性中包含 URL 一部分的任何元素,您可以使用:
这将选择 href 包含 google.com 的所有元素,例如:
正如 @BalusC 在下面的评论中所述,它还会匹配 href 中任何位置具有
google.com
的元素,例如blahgoogle.com
。If you want to get any element that has part of a URL in their href attribute you could use:
This will select all elements with a href that contains google.com, for example:
As stated by @BalusC in the comments below, it will also match elements that have
google.com
at any position in the href, likeblahgoogle.com
.http://api.jquery.com/attribute-equals-selector/
http://api.jquery.com/attribute-equals-selector/
是的。
http://api.jquery.com/attribute-equals-selector/
Yes.
http://api.jquery.com/attribute-equals-selector/