<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, '&amp;');
    alert(picpath_true[i]+'\n'+temp_entity);
}
</script>
其他的问题吧,
我测试没问题呀

解决方案 »

  1.   

    to jinjuduo():因为不同页面间的代码关系有点复杂,我暂时不能提供较完整的代码,您猜测,可能是什么问题呢?
      

  2.   

    picpath_true取不到值可能性大
    你alert(picpath_true[i])试试
      

  3.   

    <script>   
    var pattern = /&/g
    var str="a&b&cad&asi";
    var str2;
       function test() {
      str2=str.replace(pattern,"&amp");
      alert(str2);
       }
    </script>
    可以
    奇怪了,你试着像我这样先定义个正则看看
      

  4.   

    谢谢 jinjuduo() 和 Ischema(花客)!确实是数组没取到值。
      

  5.   

    我是lz,现在的情况是:picpath_true数组取到值了,但“&”到“&amp;”的替换仍不起作用 :(
      

  6.   

    picpath_true数组取到值
    的值是什么,包含&吗?
      

  7.   

    我这样试验的:picpath_true数组中有3个值,分别是:
    '{A_PIC_SHOW}perfee=0&kind=picture&img_id=b05111003&CPID=80007'
    '{A_PIC_SHOW}perfee=0&kind=picture&img_id=b05111004&CPID=80007'
    '{A_PIC_SHOW}perfee=0&kind=picture&img_id=b05111005&CPID=80007'
      

  8.   

    alert(picpath_true[i]+'\n'+temp_entity);
    我就纳闷了,你不是显示了替换前与替换后的值了吗?
    一看不就清楚是replace函数没起作用还是没取到值?
    另外偿试下其它形式的写法,或者换个环境测试
      

  9.   

    <script>
    var picpath_true=new Array('{A_PIC_SHOW}perfee=0&kind=picture&img_id=b05111003&CPID=80007','{A_PIC_SHOW}perfee=0&kind=picture&img_id=b05111004&CPID=80007','{A_PIC_SHOW}perfee=0&kind=picture&img_id=b05111005&CPID=80007')var temp_entity = '';
    for(var i=0; i<picpath_true.length; i++) { 
        temp_entity = picpath_true[i].replace(/&/g, '&amp;');
        alert(picpath_true[i]+'\n'+temp_entity);
    }
    </script>
    没问题呀,??
      

  10.   

    <!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, '&amp;');
    alert(picpath_true[i]+'\n'+temp_entity);
    }
    //-->
    </SCRIPT>
    </BODY>
    </HTML>没问题。还有其他信息提供吗?
      

  11.   

    我贴一下较完整的代码:main_editor.html中:<script>
    var picpath_true = new Array();
    var picpath_prvw = new Array();
    var temp_html = '';
    var temp_entity = '';
    var i = 0;
    </script>
    <td><input type="button" value="预览" onclick="if(this.value=='预览') { document.getElementById('preview').style.display='block'; document.getElementById('preview').innerHTML=frames['editor'].document.body.innerHTML.replace(/{APP_WAP_HOST}wap_show/g, '../show_prvw'); for(var i=0; i<picpath_true.length; i++) { temp_entity=picpath_true[i].replace(/&/g, '&amp;'); temp_html=document.getElementById('preview').innerHTML.replace(temp_entity, picpath_prvw[i]); } document.getElementById('preview').innerHTML=temp_html; this.blur(); document.getElementById('x_o').style.display='none'; hide_btn(); this.value='编辑'; } else { document.getElementById('preview').style.display='none'; display_btn(); document.getElementById('x_o').style.display='block'; this.value='预览'; }" /></td>
    在a_child.html中(a_child.html与main_editor.html的关系是:mail_editor.html中弹出一个窗口a_parent.html,a_child.html是a_parent.html中的一个iframe):<dt title="点击添加" style="background: url('<{$aPics[pics].pic_path}>') no-repeat center; height: 128px;" onclick="var picpath='{A_PIC_SHOW}perfee='+document.getElementById('perfee').value+'&kind=<{$aPics[pics].kind}>&img_id=<{$aPics[pics].pic_code}>&CPID=<{$CPID}>'; handler.format('CreateLink', picpath); handler.picpath_true[handler.i]=picpath; handler.picpath_prvw[handler.i]='<{$aPics[pics].pic_path}>'; handler.i++; parent.close();"></dt>
      

  12.   

    在a_child.html中,还有:
    <script>
    var handler = parent.window.opener;
    </script>
      

  13.   

    你能确定picpath_true能够接收到值??
      

  14.   

    我是通过以下方式确定picpath_true能够接受到值的:在以上我贴出的main_editor.html的部分代码中,加入几个alert:<td><input type="button" value="预览" onclick="if(this.value=='预览') { document.getElementById('preview').style.display='block'; document.getElementById('preview').innerHTML=frames['editor'].document.body.innerHTML.replace(/{APP_WAP_HOST}wap_show/g, '../show_prvw'); for(var i=0; i<picpath_true.length; i++) { alert(picpath_true[i]); temp_entity=picpath_true[i].replace(/&/g, '&amp;'); alert(picpath_true[i]+'\n'+temp_entity); temp_html=document.getElementById('preview').innerHTML.replace(temp_entity, picpath_prvw[i]); } document.getElementById('preview').innerHTML=temp_html; this.blur(); document.getElementById('x_o').style.display='none'; hide_btn(); this.value='编辑'; } else { document.getElementById('preview').style.display='none'; display_btn(); document.getElementById('x_o').style.display='block'; this.value='预览'; }" /></td>
    alert出的内容说明picpath_true数组接收到了值
      

  15.   

    关键在for循环那块:for(var i=0; i<picpath_true.length; i++) { alert(picpath_true[i]); temp_entity=picpath_true[i].replace(/&/g, '&amp;'); alert(picpath_true[i]+'\n'+temp_entity); temp_html=document.getElementById('preview').innerHTML.replace(temp_entity, picpath_prvw[i]); }
      

  16.   

    onclick="if(this.value=='预览') { document.getElementById('preview').style.display='block'; document.getElementById('preview').innerHTML=frames['editor'].document.body.innerHTML.replace(/{APP_WAP_HOST}wap_show/g, '../show_prvw'); for(var i=0; i<picpath_true.length; i++) { temp_entity=picpath_true[i].replace(/&/g, '&amp;'); temp_html=document.getElementById('preview').innerHTML.replace(temp_entity, picpath_prvw[i]); } document.getElementById('preview').innerHTML=temp_html; this.blur(); document.getElementById('x_o').style.display='none'; hide_btn(); this.value='编辑'; } else { document.getElementById('preview').style.display='none'; display_btn(); document.getElementById('x_o').style.display='block'; this.value='预览'; }" 你的这部分代码无法让人轻易地读出来。
    建议你把它写成的函数的形式。
    这些代码别人也不能调试。
    但是可以肯定的说你的替换的代码没有问题。