替换字符的问题 我把这段js插入到源码中.然后<img src="http://www.xxx.com/old/logo.gif " />还是无法显示.logo.gif的目录现在为new 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <script language="javascript" type="text/javascript"> var str = '这里应该是网页的所有源代码';var reg = /http:\/\/www.xxx.com\/old\//gi alert(str.replace(reg ,'http://www.xxx.com/new/' )); </script> str必须是网页的的所有源代码,而且不能只替换old,应该考虑有可能网页中有old这个单词,应该上面的代码能够保证只替换超链接中的old。我觉得用JS不是个好方法,因为这样一来每次打开网页都会用JS处理一次,这样会降低网页速度。建议:用Perl或者PHP或者其它方法,将所有网页文件读入,然后用正则表达式替换所有链接,然后输出新的文件,这样比较好。 我的问题是我把这段JS插入直接没反映啊.而old实际上是多极目录如 2/3/不存在和其他字符重复的问题 JS的话,试试这样啊<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title></head><body><img src="http://www.google.cn/options/icons/blogsearch.gif" /><img src="http://www.google.cn/options/icons/blogsearch.gif" /><script type="text/javascript">window.onload = function(){ var imgs = document.images; for(var i=0;i<imgs.length;i++) imgs[i].src = imgs[i].src.replace(/blogsearch/ig,"toolbar");}</script></body></html> 没有反应的原因:你写的JS只是用来操作字符串的,而没有对DOM的属性进行修改,5楼的方法是正确的,用Javascript修改所有的<img>元素的src属性的值。按照你的要求可以将上面的代码修改如下:<html xmlns="http://www.w3.org/1999/xhtml"><head><title></title></head><body><img src="http://www.xxx.com/old/logo1.gif " /><img src="http://www.xxx.com/old/logo2. gif " /><script type="text/javascript">window.onload = function(){ var imgs = document.images; for(var i=0;i<imgs.length;i++) imgs[i].src = imgs[i].src.replace(/old/ig,"new");}</script></body></html> 恩.可以用.还是有个疑问<html xmlns="http://www.w3.org/1999/xhtml"><head><title></title></head><body><img src="/DownFiles/Book/0/622/2008/11/4/20081104083750395.gif" align="center" border=0><script type="text/javascript">window.onload = function(){ var imgs = document.images; for(var i=0;i<imgs.length;i++) imgs[i].src = imgs[i].src.replace(/\/DownFiles\//ig,"http:\/\/8kk8.net\/DownFiles\/");}</script></body></html>这样的话.图片还是打不开.显示的图片地址怎么是http://xxx.com/DownFiles/Book/0/622/2008/11/4/20081104083750395.gif实际的网站地址被附加到了图片地址前面..这怎么解决? http://xxx.comhttp://8kk8.net/DownFiles/Book/0/622/2008/11/4/20081104083750395.gif imgs[i].src.replace(/^.*?\/DownFiles\//ig,"http:\/\/8kk8.net\/DownFiles\/"); 改为这样<html xmlns="http://www.w3.org/1999/xhtml"><head><title></title></head><body><img src="/DownFiles/Book/0/622/2008/11/4/20081104083750395.gif" align="center" border=0><script type="text/javascript">window.onload = function(){ var imgs = document.images; for(var i=0;i<imgs.length;i++) imgs[i].src = imgs[i].src.replace(/.*DownFiles\//ig,"http:\/\/8kk8.net\/DownFiles\/"); }</script></body></html> 求struts2的小项目练手 JQuery 的 disabled 问题 js 兼容IE 如何简单的实现"页面每10秒中自动刷新一次"? ext autoload 加载一个panel的问题 <input type='file'>标签的问题 高手帮忙!很难的啊。烦啊!说你是高手要作到才行啊~~~~ 急死了,北京的程序员租了二居,还剩一间现招租 一个跳转页面的问题? 用户登录时进行加密处理 求一正则表达式 如何将两个文本框的值进行计算,并且将计算结果返回到另外一个文本框,急急急急急急急急急急急急急急急急!!!!!!!!!!!!!!!
var str = '这里应该是网页的所有源代码';
var reg = /http:\/\/www.xxx.com\/old\//gi
alert(str.replace(reg ,'http://www.xxx.com/new/' ));
</script> str必须是网页的的所有源代码,而且不能只替换old,应该考虑有可能网页中有old这个单词,应该上面的代码能够保证只替换超链接中的old。我觉得用JS不是个好方法,因为这样一来每次打开网页都会用JS处理一次,这样会降低网页速度。建议:用Perl或者PHP或者其它方法,将所有网页文件读入,然后用正则表达式替换所有链接,然后输出新的文件,这样比较好。
不存在和其他字符重复的问题
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<img src="http://www.google.cn/options/icons/blogsearch.gif" />
<img src="http://www.google.cn/options/icons/blogsearch.gif" />
<script type="text/javascript">
window.onload = function()
{
var imgs = document.images;
for(var i=0;i<imgs.length;i++)
imgs[i].src = imgs[i].src.replace(/blogsearch/ig,"toolbar");
}
</script>
</body>
</html>
没有反应的原因:你写的JS只是用来操作字符串的,而没有对DOM的属性进行修改,5楼的方法是正确的,用Javascript修改所有的<img>元素的src属性的值。
按照你的要求可以将上面的代码修改如下:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<img src="http://www.xxx.com/old/logo1.gif " />
<img src="http://www.xxx.com/old/logo2. gif " />
<script type="text/javascript">
window.onload = function()
{
var imgs = document.images;
for(var i=0;i<imgs.length;i++)
imgs[i].src = imgs[i].src.replace(/old/ig,"new");
}
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<img src="/DownFiles/Book/0/622/2008/11/4/20081104083750395.gif" align="center" border=0>
<script type="text/javascript">
window.onload = function()
{
var imgs = document.images;
for(var i=0;i<imgs.length;i++)
imgs[i].src = imgs[i].src.replace(/\/DownFiles\//ig,"http:\/\/8kk8.net\/DownFiles\/");
}
</script>
</body>
</html>
这样的话.图片还是打不开.显示的图片地址怎么是http://xxx.com/DownFiles/Book/0/622/2008/11/4/20081104083750395.gif
实际的网站地址被附加到了图片地址前面..
这怎么解决?
<head>
<title></title>
</head>
<body>
<img src="/DownFiles/Book/0/622/2008/11/4/20081104083750395.gif" align="center" border=0>
<script type="text/javascript">
window.onload = function()
{
var imgs = document.images;
for(var i=0;i<imgs.length;i++)
imgs[i].src = imgs[i].src.replace(/.*DownFiles\//ig,"http:\/\/8kk8.net\/DownFiles\/");
}
</script>
</body>
</html>