How can I hide a label after few seconds using goo

2019-06-09 16:36发布

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!!

2条回答
乱世女痞
2楼-- · 2019-06-09 16:43

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;
}
查看更多
女痞
3楼-- · 2019-06-09 16:43

Progress indicator solution etc, this works. It lets you chain events, I have used it several times.

Updating a widget value on the go. productforums.google.com/d/topic/apps-script/lABoP-cJcGQ/…

查看更多
登录 后发表回答