开发者

Add domain to relative urls

How can I add http://facebook.com to relative URL's contained within #facebook_urls? Eg:

<a href="/test.html">

becomes

<a href="http://facebook.com/test.html">

#facebook_urls also co开发者_JAVA技巧ntains absolute urls, so I want to make sure I don't touch those.


Something like this?

$('#facebook_urls a').each(function() {
  if(!this.href.match('^http')) {
    this.href = "http://facebook.com/" + this.href
  }
})
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜