简体   繁体   English

Google Apps脚本:如何在悬停时更改标签的文本颜色?

[英]Google Apps Script: How to change text color of label on hover?

I am using Google Apps Script and am relativly new to it. 我正在使用Google Apps脚本,但相对来说还很陌生。 I am wondering if there is a way to change the color of text for a label when hovering over it with a mouse? 我想知道当用鼠标悬停在标签上时是否可以更改标签文本的颜色吗? Like how sometimes hyperlinks change color when hovering over them. 就像有时超链接悬停在其上时如何改变颜色。 To be clear, this question is asking about how to do it with labels and not hyperlinks. 明确地说,这个问题是关于如何使用标签而不是超链接的问题。

Client handlers are made for this. 客户处理程序就是为此而设计的。 Try using styleAttributes and MouseOver / mouseOutHandler like in the example below. 尝试使用styleAttributesMouseOver / mouseOutHandler ,如下面的示例所示。 ( test code available here ) 此处提供测试代码

function doGet() {
  var app = UiApp.createApplication().setTitle('test hover');
  var label = app.createLabel('Hover test here');
  var handlerOver = app.createClientHandler().forEventSource().setStyleAttributes({'color':'red'});
  var handlerOut = app.createClientHandler().forEventSource().setStyleAttributes({'color':'black'});
  label.addMouseOverHandler(handlerOver).addMouseOutHandler(handlerOut);
  app.add(label);
  return app;
}

You need to use the mouseover and mouseout events to accomplish this, the below example should help you 您需要使用mouseover和mouseout事件来完成此操作,以下示例应为您提供帮助

     function doGet() {
       var app = UiApp.createApplication();
       var text = app.createTextBox().setName("text");
       text.addMouseOverHandler(app.createClientHandler().forEventSource().setStyleAttribute("background-color", "yellow"));
       text.addMouseOutHandler(app.createClientHandler().forEventSource().setStyleAttribute("background-color", "white"));    
       app.add(text);
       return app;
     }

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM