Welcome 微信登录

首页 / 脚本样式 / JavaScript / javascript replace

javascript replace2008-05-09str="/"+obj.value+"/g";
alert(str);
string=string.replace(str,"");
window.document.all.Cag.value=string;

那里错了 为什么不能将 str 中 obj.value 的变量的内容替换为空?

str是字符串"/abc/g"(假如obj.value = "abc"),而不是正则表达式/abc/g

可以直接这样写而不用正则表达式:string = string.replace(obj.value,"")