求一个替换文字函数 <body>321<body>我要替换321为 123 怎么替换 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你是要反序输出?<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title></title><script language="JavaScript" type="text/javascript">function test(val){ var a=val.split(""); var tmpret=[]; var ret; for(var i=a.length-1;i>=0;i--){ tmpret[tmpret.length]=a[i]; } ret=tmpret.join("") alert(ret)} window.onload=function(){ var str= "123" test(str) }</script></head><body></body></html> <body>321 rewrewfdsfds321<body>这样 我要替换里面的所有的321 为ABC不是反序 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>无标题文档</title></head><body><script type="text/javascript"></script><script>document.body.replace("会员价","现价")</script> <body>dsaa会员价</body></body></html>不好使 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>无标题文档</title></head><body><script type="text/javascript">document.body.replace("会员价","现价");</script> <body>dsaa会员价</body></body></html>从发下 刚才那个少个分号这样的 不好使 写错一点<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>无标题文档</title></head><body><script type="text/javascript">window.onload=function(){var str=document.body.innerText;document.body.innerText=str.replace("会员价","现价")}</script> <body>dsaa会员价</body></body></html> 楼主可以试试这个。<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>无标题文档</title></head><body><span>dsaa会员价</span><script type="text/javascript">document.body.innerHTML=document.body.innerHTML.replace("会员价","现价");</script></body></html> 全部匹配replace(/会员价/g,"现价"); replace搞了半天没出 只好写了个function replaceStr(str,newStr,oldStr){ var temp=""; var resultStr=""; for(var i=0;i<str.length;i++){ temp=str.substring(i,i+newStr.length); if(temp==oldStr){ if(i==0){ resultStr=temp+str.substring(newStr.length,str.length); }else{ resultStr=str.substring(0,i)+newStr+str.substring(i+temp.length,str.length); str=resultStr; } } } return resultStr;} replace(/会员价/g,"现价");这个不好使 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>无标题文档</title></head><script type="text/javascript">replace(new RegExp("会员价","g"),"现价");</script> <body>dsaa会员价</body></html>这样不行replace(/会员价/g,"现价");8楼的这个的语法有错误 我用DW现实不出来 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>无标题文档</title></head><body><span>dsaa会员价</span><script type="text/javascript">document.body.innerHTML=document.body.innerHTML.replace("会员价","现价");</script></body></html>这句话总出现WINDOWS错误提示 然后强制关闭 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>无标题文档</title></head> <body> dsaa会员价dsaa会员价dsaa会员价dsaa会员价dsaa会员价</body><script type="text/javascript">document.body.innerHTML = document.body.innerHTML.replace(new RegExp("会员价","g"),"现价");</script></html> <html> <head> <title> New Document </title> <script> function init() { var text = document.body.innerText; var str = text.replace(/321/g,123); document.body.innerText = str; } </script> </head> <body onload="init();"> 321 </body></html> 按道理 14楼的大哥的 应该好使啊实际上也好使但为什么document.body.innerHTML = document.body.innerHTML.replace(new RegExp("会员价","g"),"现价"); 之后 我原来的一些格式被改变了呢 replace(/会员价/gi,"现价"); 嘿嘿,这个样更好啦,忽略大小写啦~ jquery 使元素在固定空间内滚动 这段代码是在干嘛?调用一个函数?声明一个class? javascript如何替代字符? 为什么window.history[0]取不到上一个访问的url? 【求助】如何清理IE内存中的JS变量?各位大侠,Help啊 请问setAttribtue()是否支持name属性? 请教如何将div做成屏幕居中,类似sina.com的首页那样? 奇怪的Cookie问题 上下移动页和多项选择页怎么实现?需要高手!!!!!! java虚拟机 JS里变量和字符的连接. firefox中加了头声明图片无法滚动
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
<script language="JavaScript" type="text/javascript">function test(val){
var a=val.split("");
var tmpret=[];
var ret;
for(var i=a.length-1;i>=0;i--){
tmpret[tmpret.length]=a[i];
}
ret=tmpret.join("")
alert(ret)
}
window.onload=function(){
var str= "123"
test(str)
}</script>
</head>
<body></body>
</html>
这样 我要替换里面的所有的321 为ABC
不是反序
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head><body>
<script type="text/javascript"></script>
<script>
document.body.replace("会员价","现价")
</script>
<body>dsaa会员价</body>
</body>
</html>
不好使
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head><body>
<script type="text/javascript">document.body.replace("会员价","现价");
</script>
<body>dsaa会员价</body>
</body>
</html>
从发下 刚才那个少个分号这样的 不好使
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head><body>
<script type="text/javascript">
window.onload=function(){
var str=document.body.innerText;
document.body.innerText=str.replace("会员价","现价")}</script>
<body>dsaa会员价</body>
</body>
</html>
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head><body>
<span>dsaa会员价</span>
<script type="text/javascript">
document.body.innerHTML=document.body.innerHTML.replace("会员价","现价");
</script>
</body>
</html>
var temp="";
var resultStr="";
for(var i=0;i<str.length;i++){
temp=str.substring(i,i+newStr.length);
if(temp==oldStr){
if(i==0){
resultStr=temp+str.substring(newStr.length,str.length);
}else{
resultStr=str.substring(0,i)+newStr+str.substring(i+temp.length,str.length);
str=resultStr;
}
}
}
return resultStr;
}
这个不好使
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head><script type="text/javascript">
replace(new RegExp("会员价","g"),"现价");
</script> <body>dsaa会员价
</body>
</html>
这样不行
replace(/会员价/g,"现价");
8楼的这个的语法有错误 我用DW现实不出来
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head><body>
<span>dsaa会员价</span>
<script type="text/javascript">
document.body.innerHTML=document.body.innerHTML.replace("会员价","现价");
</script>
</body>
</html>
这句话总出现WINDOWS错误提示 然后强制关闭
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
dsaa会员价dsaa会员价dsaa会员价dsaa会员价dsaa会员价
</body>
<script type="text/javascript">
document.body.innerHTML = document.body.innerHTML.replace(new RegExp("会员价","g"),"现价");
</script>
</html>
<head>
<title> New Document </title>
<script>
function init()
{
var text = document.body.innerText;
var str = text.replace(/321/g,123);
document.body.innerText = str;
}
</script>
</head> <body onload="init();">
321
</body>
</html>
之后 我原来的一些格式被改变了呢