<div id="wc">D:\wwwnew\WebApplication1\1.gif</div>
<script type="text/javascript" defer="defer">
var wc = document.getElementById("wc");
//替换后字符串"D:\\wwwnew\\WebApplication1\\1.gif" 
alert(wc.innerHTML.replace(/\\/g, "\\\\"));
</script>

解决方案 »

  1.   

    注意,如果你那个源串是
    "D:\wwwnew\WebApplication1\1.gif"
    的话首先这个串就有问题。。
    你可以alert下看看
      

  2.   

    谢谢 muxrwc(需时越兔) ( ) 信誉:100 <input name="file1" id="file1" type="file" /> 源串这样得到
    我想这个串没有问题.
      

  3.   

    <HTML>
    <HEAD>
    <title>WebForm1</title>
    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <meta content="C#" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"> </HEAD>
    <body>
    <form name="Form1" method="post" action="WebForm1.aspx" id="Form1" enctype="multipart/form-data">
    <P>
    <input name="file1" id="file1" type="file" onpropertychange="btn(this);" /><table id="imgfile" border="0">
    <tr>
    <td></td>
    </tr>
    </table>
    <script language='javascript'>
    function btn(obj)
    {
    var imgvalue=obj.value;
    document.all('imgfile').rows[0].cells[0].innerHTML="<input type='image'  onerror='alert(\"类型错误或者目标不存在!\");'   src='"+imgvalue+"' alt='' border='0' width='30' height='30' onclick=\"javascript:window.open('"+imgvalue+"','','dialogWidth:500px; dialogHeight:500px; scroll:no; center:yes; help:no; resizable:no; status:no;');return false;\" />";}</script><input type="submit" name="Button1" value="Button" id="Button1" /></P>
    <P><FONT face="宋体"></FONT>&nbsp;</P>
    </form>
    </body>
    </HTML>
      

  4.   

    window.open那个拒绝访问  - -权限问题这里也没涉及到你说的那个式子啊。
      

  5.   

    window.open("D:\\wwwnew\\WebApplication1\\1.gif" );
    这样就没有错了.所以我想把字符串转成这样.我是ie6不行呀.
    请问这个有什么办法解除吗?
      

  6.   

    <HTML>
    <HEAD>
    <title>WebForm1</title>
    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <meta content="C#" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"></HEAD>
    <body>
    <form name="Form1" method="post" action="WebForm1.aspx" id="Form1" enctype="multipart/form-data">
    <P>
    <input name="file1" id="file1" type="file" onpropertychange="btn(this);" /><table id="imgfile" border="0">
    <tr>
    <td></td>
    </tr>
    </table>
    <script language='javascript'>
    function btn(obj)
    {
    var imgvalue=obj.value;
    imgvalue=imgvalue.replace(/\\/g,"\\\\");
    document.all('imgfile').rows[0].cells[0].innerHTML="<input type='image'  onerror='alert(\"类型错误或者目标不存在!\");'   src='"+imgvalue+"' alt='' border='0' width='30' height='30' onclick=\"javascript:window.open('"+unescape(imgvalue)+"','','dialogWidth:500px; dialogHeight:500px; scroll:no; center:yes; help:no; resizable:no; status:no;');return false;\" />";
    alert(document.all('imgfile').rows[0].cells[0].innerHTML)}</script><input type="submit" name="Button1" value="Button" id="Button1" /></P><P><FONT face="宋体"></FONT>&nbsp;</P>
    </form>
    </body>
    </HTML>
      

  7.   

    迷糊可以open?IE6测试是权限不足啊FF就更不用说了