获取用 javascript 编写的 href 属性
我想获得一个 href 属性,因为它出现在 html 中 - 而不是完全限定的 url。
<a href="foo.html">foo</a>
$('a[href]').each(function(){
alert(this.href);
});
获取以 http:// 开头的绝对 URL。我希望它能得到“foo.html”。
I would like to get an href attribute as it appears in the html - instead of a fully qualified url.
<a href="foo.html">foo</a>
$('a[href]').each(function(){
alert(this.href);
});
Gets an absolute url starting with http:// . I'd like it to get "foo.html" instead.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试
.attr('href')
获取 href 值。Try
.attr('href')
to get the href value.您需要更改元素的循环方式以及使用
this
的方式:这里是工作示例。
You will need to alter the way you loop through the element, and the way you use
this
:Working example here.