Chinaunix

标题: JavaScript的问题 [打印本页]

作者: jiannma    时间: 2010-05-14 14:44
标题: JavaScript的问题
本帖最后由 jiannma 于 2010-05-14 14:47 编辑

最近遇到了关于javascript替换文件的问题,网上也搜索了好半天,还是没有解决。。。

效果图为:


想用新文件替换旧文件,js代码如下:


  1. <html>
  2. <head>
  3. <script type="text/javascript">

  4. function show_filename()
  5. {
  6.         var file1 = document.getElementById('eve1').value;
  7.         var file2 = document.getElementById('eve2').value;

  8.         var r = confirm("Are you sure?");
  9.         if(r==true){

  10.         var myObject,newpath
  11.         myObject = new ActiveXObject("Scripting.FileSystemObject");
  12.         [color=Red][b]newpath = myObject.CopyFile("file1","file2");[/b][/color]

  13.         alert("Success!");
  14.         }
  15.         else{
  16.         alert("You pressed Cancel!");
  17.         }


  18. /*
  19.         alert(file1);
  20.         alert(file2);

  21. */
  22. }
  23. </script>
  24. </head>
  25. <body>

  26. <form>
  27.         <p>
  28.         New File:<input name = "text1" type = "file" id = "eve1">
  29.         </p>

  30.         <p>
  31.         Old File:<input name = "text2" type = "file" id = "eve2">
  32.         </p>

  33.         <p>
  34.         <input type = "button" name ="submit"  value = "replace" onclick = "show_filename()">
  35.         </p>
  36. </form>
  37. </body>
  38. </html>
  39.        

复制代码
红色的部分是遇到的问题,也就是下面的一行内容:
newpath = myObject.CopyFile("file1","file2");


各位DX们,能看看这行该怎么修改呢?偶是js新手。谢谢...
作者: zhoumiao    时间: 2010-05-14 15:20
file1,file2是两个变量?newpath = myObject.CopyFile("file1","file2"加双引号就成常量了吧
作者: jiannma    时间: 2010-05-14 15:44
回复 2# zhoumiao


    谢谢  我尝试了 还真是。。。哎。。 低级错误啊
作者: jiannma    时间: 2010-05-17 10:39
如果旧的文件是处在打开的状态,更新后想有个提示:“xxx已更新,要载入更新后的内容?”。。

这个如何实现呢?
作者: zhoumiao    时间: 2010-05-17 11:21
俺有个疑问,如果文件正被打开,还能覆盖它么?
作者: jiannma    时间: 2010-05-17 13:23
回复 5# zhoumiao


    我觉得好象不可以把 。。。
作者: zhoumiao    时间: 2010-05-17 13:25
那这个提示还有必要么
作者: 0vk0    时间: 2010-05-19 18:56
如果文件正被打开,在win下不能覆盖它么




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2