<SCRIPT LANGUAGE="JavaScript">
<!--
function replaceSrc(baseUrl,html)
{ var r = /src=([\'\"]?)([^\'\"]*?)\1/gi; var u = baseUrl.replace("http:\/\/",""); if(u.indexOf("\/")>=0)
{
baseUrl = "http:\/\/" + u.substring(0,u.indexOf("\/")+1);
}
else
{
baseUrl = "http:\/\/" + u;
}
html = html.replace(r,function(){if(arguments[2].indexOf("http:\/\/")>=0){ return arguments[0];} else {return arguments[0].replace(arguments[2],baseUrl + arguments[2]);}}); return html;}var htm = "hello <a src=\"a.htm\">asdfd</a><img src='a.jpg'>";alert(replaceSrc("http://www.google.com/",htm));
//-->
</SCRIPT>
<!--
function replaceSrc(baseUrl,html)
{ var r = /src=([\'\"]?)([^\'\"]*?)\1/gi; var u = baseUrl.replace("http:\/\/",""); if(u.indexOf("\/")>=0)
{
baseUrl = "http:\/\/" + u.substring(0,u.indexOf("\/")+1);
}
else
{
baseUrl = "http:\/\/" + u;
}
html = html.replace(r,function(){if(arguments[2].indexOf("http:\/\/")>=0){ return arguments[0];} else {return arguments[0].replace(arguments[2],baseUrl + arguments[2]);}}); return html;}var htm = "hello <a src=\"a.htm\">asdfd</a><img src='a.jpg'>";alert(replaceSrc("http://www.google.com/",htm));
//-->
</SCRIPT>
解决方案 »
- extjs问题
- 帮忙看看这段JS在火狐下为什么不能用,怎么改,才能兼容火狐
- 请问阿信的三级连动菜单怎么打开后显示为selected
- 像这样的语句能不能换一种写法啊?
- 高手,帮忙解决这个JavaScript运行问题,急!!
- 请问js能否实现,捕获某个IE窗口的句柄,并且将其关闭,而不是将整个进程杀掉。高手请进。
- 能不能用javascript打开文本文件,要用记事本打开
- 关于links 的onclick事件问题?? 怎么在body 的 onLoad 事件中禁用 所有的联接???
- 怎样让用户单击一个链接,就自动启动word打开word文档?
- 能不能用js写一个类似于word的公式编辑器?
- 简单又“奇怪”的随机数问题!
- js如何得到flash文件的原高和宽
<script language=javascript>
str="<a href=\"/lo/index.html\"><a href=\"./go.html\">";
re=/(<a\s+href\s*=\s*\")(\.|\/lo)([^\"]*)(\"\s*>)/gi
alert(str.replace(re,"$1http://www.xxx.com/lo$3$4"))
</script>
var testString="<A Href=\"/lo/index.html\">aaa</a><a href=\"./ww/default.asp\">";
alert(testString.replace(/(\<\a\shref=\")([^\"]+)/ig,function($0,$1,$2){return $1+"http://www.xxx.com"+$2.replace(/^\.{1}/,"")}));
</script>