我的页面链接中有超链接
<a href="home.php?id=2">some text</a>
<a href="http://myDomanin.com/home.php?id=3">some text</a>
<a href="http://myDomanin.com/home.php?id=4">some text</a>
<a href="home.php?id=5">some text</a>
我想编写一个javascript来将href更改为这个新链接:
如果OldHref = http://myDomanin.com/home.php?id=3
则
NewHref = http://myNewDomain.com/{base64Encode of OldHref}
找到一个插件来制作base64编码here
答案 0 :(得分:3)
$('a').each(function(){
this.href = 'http://myNewDomain.com/' + Base64Encode(this.href);
});
或类似的......
非,jQuery方法:
var anchors = document.getElementsByTagName('a');
for (var a = 0; a < anchors.length; a++){
anchors[a].href = 'http://myNewDomain.com/' + Base64Encode(anchors[a].href);
}