如何使用谷歌应用程序脚本几秒钟后隐藏标签? [英] How can I hide a label after few seconds using google apps script?

查看:124
本文介绍了如何使用谷歌应用程序脚本几秒钟后隐藏标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的应用程序,用户按下按钮并显示欢迎消息。我需要这个消息(标签)在几秒钟后隐藏,比如说5秒。
我在google apps脚本中找不到像setTimeout()这样的函数。



有人可以告诉我如何实现这个功能吗?



(你可以看到,不是一个有经验的程序员)。

谢谢!!

解决方案

一种可能的解决方案。逻辑是有两个按钮点击处理程序。第一个使标签可见,第二个隐藏标签5秒后隐藏标签。

 函数doGet(e){ 
var app = UiApp.createApplication();
var panel = app.createVerticalPanel();
var btn = app.createButton()。setText('Test');
var lblVisible = app.createLabel('Visible Test')。setVisible(false).setId('lblVisible');
panel.add(btn);
panel.add(lblVisible);
var handler = app.createServerHandler('onBtnClick');
var handlerWait = app.createServerHandler('onWaitEvent');
handler.addCallbackElement(panel);
handlerWait.addCallbackElement(panel);
btn.addClickHandler(handler);
btn.addClickHandler(handlerWait);
app.add(panel);
返回应用程序;
}

函数onWaitEvent(e){
Utilities.sleep(5 * 1000);
var app = UiApp.getActiveApplication();
var lblVisible = app.getElementById('lblVisible');
lblVisible.setVisible(false);
返回应用程序;
}

function onBtnClick(e){
var app = UiApp.getActiveApplication();
var lblVisible = app.getElementById('lblVisible');
lblVisible.setVisible(true);
返回应用程序;
}


I have a simple application where the user press a button and a welcome message is shown. I need this message(label) to be hidden after few seconds, say 5 secs. I couldn't find a function like setTimeout() in google apps script.

Can someone give an idea how I could implement this?

(as you can see, not an experienced programmer).

Thanks!!

解决方案

A possible solution. The logic is to have two the button click handlers. the 1st one makes the label visible and the 2nd one sleeps 5 seconds and after hides the label.

function doGet(e) {
  var app = UiApp.createApplication();
  var panel = app.createVerticalPanel();
  var btn = app.createButton().setText('Test');
  var lblVisible = app.createLabel('Visible Test').setVisible(false).setId('lblVisible');
  panel.add(btn);
  panel.add(lblVisible);
  var handler = app.createServerHandler('onBtnClick');
  var handlerWait = app.createServerHandler('onWaitEvent');
  handler.addCallbackElement(panel);
  handlerWait.addCallbackElement(panel);
  btn.addClickHandler(handler);
  btn.addClickHandler(handlerWait);
  app.add(panel);
  return app;
}

function onWaitEvent(e) {
  Utilities.sleep(5 * 1000);
  var app = UiApp.getActiveApplication();
  var lblVisible = app.getElementById('lblVisible');
  lblVisible.setVisible(false);
  return app;
}

function onBtnClick(e) {
  var app = UiApp.getActiveApplication();
  var lblVisible = app.getElementById('lblVisible');
  lblVisible.setVisible(true);
  return app;
}

这篇关于如何使用谷歌应用程序脚本几秒钟后隐藏标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆