简体   繁体   English

如何在Google脚本中为按钮分配功能

[英]How can I assign a function to a button in google script

I created a prompt in google script, with two buttons. 我在Google脚本中创建了一个带有两个按钮的提示。 If clicked OK, I want a function to run, if not, a dialog says "The user clicked no". 如果单击“确定”,则我希望某个功能运行,否则,对话框将显示“用户单击否”。 The buttons are generated correctly, and the function works. 按钮正确生成,并且该功能起作用。 I know this, 'cause I know how to assign it to an item menu. 我知道这一点,因为我知道如何将其分配给项目菜单。

makefile is the function I'm trying to run makefile是我要运行的功能

function AFIP() {
    var ui = SpreadsheetApp.getUi() 
    var response =   ui.alert('Title', 'Yo want to generare the file?',
                     ui.ButtonSet.OK_CANCEL);

    if (response == ui.Button.OK) {
        makefile;
    } else {
        Logger.log('The user clicked "No" or the close button in the dialog\'s title  bar.');
    }
}

Using this for the definition of the makefile function: 使用它来定义makefile函数:

function makefile() {
  Logger.log("makefile() has been executed.");
}

Your code works, with one change. 您的代码可以工作,只需更改一下即可。 Instead of: 代替:

makefile;

It should be: 它应该是:

makefile();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将每个功能或方法分配给按钮? - How can i assign each function or method to a button? 如何将键盘笔划分配给按钮? - How can i assign a Keyboard stroke to a button? Google脚本:我无法将值分配给对象的键 - Google Script: i can not assign a value to a key of an object [Google script]如何从表单提交中分配生成的编辑响应URL,然后将其分配给确认email中的按钮? - [Google script]How to assign generated edit response URL from a form submission and then assign it to a button in confirmation email? Google 电子表格:将脚本分配给带有参数的按钮 - Google spreadsheets: Assign a script to a button with parameters 如何将模态表单组件打开功能分配给任何其他按钮组件 - How can I assign modal form component opening function to any another button component 我可以通过与侧边栏中的按钮关联的 function 操作基于 html 的 Google Apps 脚本侧边栏中的文本框吗? - Can I manipulate a Textbox in an html based Google Apps Script Sidebar through a function associated to a button in that Sidebar? 如何使用 javascript 变量分配 Google Apps 脚本变量? - How do I assign Google Apps Script variable with javascript variable? 如何将 function 分配给 React 中另一个组件的按钮? - How do I assign a function to a button from another component in React? 如何将变量从HTML脚本文件传递到Google Apps脚本中的javascript函数? - How can I pass a variable from an HTML script file to a javascript function in google apps script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM