filePath = filePath.replace("\","\\");
我想将所有"\"替换为"\\",谢谢

解决方案 »

  1.   

    sUrl = sUrl.replace("@","%40");
    sUrl = sUrl.replace("#","%23");
    sUrl = sUrl.replace("(","%28");
    sUrl = sUrl.replace(")","%29");
    sUrl = sUrl.replace("=","%3D");
    sUrl = sUrl.replace(";","%3B");
    sUrl = sUrl.replace("'","%27");
    楼主你查一下编码
      

  2.   

    filePath = filePath.replace(/\\/g,"\\\\")
      

  3.   


     function readExcel()
     { 
    var filePath = document.form1.upfile.value; 
    filePath = filePath.replace(/\\/g,"\\\\");
    var excelApp = new ActiveXObject("Excel.application"); 
     try{
        var oWB = excelApp.Workbooks.open(filePath); 
     }catch(e){
      alert('打开文件失败!');
     }  var oSheet = oWB.Worksheets(1);
      alert(oSheet.Cells(1,1).value);
      alert(oSheet.UsedRange.rows.count);
      alert(oWB.Worksheets.count);
      oSheet=null;
      oWB.close();
      excelApp=null;
     }<input type="file" name="upfile"/><input type="button" onclick="readExcel();" value="读取">
    js读取excel,用了2楼的方法依然读取不到excel表,为什么呢?
      

  4.   

    filePath = filePath.replace(/\\/g,"\\\\")
      

  5.   

    自己找到办法了。
     function readExcel(id)
     { 
    var oXL = new ActiveXObject("Excel.Application"); 
    var ip = document.getElementById(id);
    ip.select();
    var filePath = document.selection.createRange().text;
    var oWB = oXL.Workbooks.open(filePath);
    var oSheet = oWB.ActiveSheet; 
    alert(oSheet.Cells(2,1).value);
    }
    <input type="file" id="attachFile" name="attachFile"/><input type="button" onclick="readExcel('attachFile')" value="读取"/>因为在较新版本的浏览器 ( Firefox3,  IE8, IE7(IE8模拟) ) 中无法获取file input的完整value,需要使用到selection.createRange()来解决。