【问题标题】:Can't pass multiple parameters in an onclick function无法在 onclick 函数中传递多个参数
【发布时间】:2019-06-10 10:00:01
【问题描述】:

我正在尝试创建一种上传机制,其中我可以使用来自 HTML 的文件 ID 将文件上传到谷歌驱动器中。我不想将文件夹的 ID 放在上传功能中,因为这是需要的。我试图通过声明另一个参数即函数上传(e,id)来传递函数上传(e)的多个参数。我知道这个 onclick="google.script.run.withSuccessHandler(updateUrl).upload(this.parentNode)"

在 HTML 中触发了该函数

我尝试通过 onclick="google.script.run.withSuccessHandler(updateUrl).upload(this.parentNode, '1234thisisanexampleid')" 添加另一个参数

其中 1234thisisanexampleid 是一个字符串。我也不确定 this.parentNode 是如何的。我也看到了在参数中添加逗号的结果,但我也不明白它是如何工作的。

 //code gs    
 function doGet() {
  return HtmlService.createHtmlOutputFromFile('Form.html');
}

function upload(e) { 



 // Folder ID of destination folder
 var destination_id = xxx;



var img = e.imageFile;

var destination = DriveApp.getFolderById(destination_id);

destination.createFile(img);

return "File Uploaded Successfully!";
}



//Form.html (just a part of the code)
<form>
  <input type="file" name="imageFile">
  <input type="button" value="Upload File" onclick="google.script.run.withSuccessHandler().upload(this.parentNode)">
</form>

【问题讨论】:

    标签: html forms google-apps-script web-applications parameters


    【解决方案1】:

    问题:

    A form element within the page is also legal as a parameter, but it must be the function’s only parameter, and it is not legal as a return value.

    正如官方文档中所写,不能发送两个参数,而其中一个是form

    解决办法:

    将其作为输入发送到表单中。

    <input type="hidden" name ="folderId" value="1234thisisanexampleid">
    

    【讨论】:

      猜你喜欢
      • 2013-12-18
      • 1970-01-01
      • 2021-11-11
      • 1970-01-01
      • 1970-01-01
      • 2012-03-27
      • 1970-01-01
      • 2014-11-05
      • 2013-12-16
      相关资源
      最近更新 更多