Uncaught SyntaxError: Unexpected token in body onload

  • 2019 年 10 月 4 日
  • 筆記

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

本文链接:https://jerry.blog.csdn.net/article/details/100824493

如下html page里的一段javascript code:

<html>  <head>  <script language="javascript">  var s = "";  function ShowFolderFileList(i,folderspec)  {    /*     var fso,f,fc,name;     var url,str,file,filename;     var i;     fso = new ActiveXObject("Scripting.FileSystemObject");     f = fso.GetFolder(folderspec);     s += i++ + "t" + f.Name + "tn";     fc = new Enumerator( f.files );     for (; !fc.atEnd(); fc.moveNext( ) ) {        filename = fso.GetFileName( fc.item( ) );        console.log("file name: " + filename);     }     fc = new Enumerator(f.SubFolders);     for (; !fc.atEnd(); fc.moveNext()) {        ShowFolderFileList(i,fc.item());     }     return( s );     */     console.log(i);     console.log(folderspec);  }  </script>  </head>  <body onload = ShowFolderFileList('test', 'c:\temp')></body>  </html>

在文件末尾提示有 syntax error:

solution: 将onload内整个函数调用用“”包裹起来: