rt
一段JS代码如下:
var temp_entity = ' ';
for(var i=0; i <picpath_true.length; i++) {
temp_entity = picpath_true[i].replace(/&/g, '& ');
alert(picpath_true[i]+ '\n '+temp_entity);
}
每次alert的结果显示,“&”都没有被替换成“&”
------解决方案--------------------
<script>
var picpath_true=new Array( 'asd&e2 ', "& ", "sy&wq ")
var temp_entity = ' ';
for(var i=0; i <picpath_true.length; i++) {
temp_entity = picpath_true[i].replace(/&/g, '& ');
alert(picpath_true[i]+ '\n '+temp_entity);
}
</script>
其他的问题吧,
我测试没问题呀
------解决方案--------------------
<script>
var pattern = /&/g
var str= "a&b&cad&asi ";
var str2;
function test() {
str2=str.replace(pattern, "& ");
alert(str2);
}
</script>
可以
奇怪了,你试着像我这样先定义个正则看看
------解决方案--------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN ">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME= "Generator " CONTENT= "EditPlus ">
<META NAME= "Author " CONTENT= " ">
<META NAME= "Keywords " CONTENT= " ">
<META NAME= "Description " CONTENT= " ">
</HEAD>
<BODY>
<SCRIPT LANGUAGE= "JavaScript ">
<!--
var picpath_true=new Array( 'asd&e2 ', "& ", "sy&wq ")
var temp_entity = ' ';
for(var i=0; i <picpath_true.length; i++) {
temp_entity = picpath_true[i].replace(/&/g, '& ');
alert(picpath_true[i]+ '\n '+temp_entity);
}
//-->
</SCRIPT>
</BODY>
</HTML>
没问题。还有其他信息提供吗?