javascript 当我试图使HTML微调器可见时,如何使用Google Script显示元素?

qoefvg9y  于 2023-01-16  发布在  Java
关注(0)|答案(1)|浏览(95)

我试图在按下按钮时显示一个旋转的加载程序。这些没有影响:

document.getElementsByClass('loader')[0].style.visibility = 'visible';

document.getElementsByClass('loader').style.visibility = 'visible';

我哪里做错了?
超文本标记语言代码

<html>
   <script>
      function clickMe() {
        document.getElementById('message').innerHTML = "mp"; 
        document.getElementsByClass('loader')[0].style.visibility = 'visible';
        google.script.run.withSuccessHandler(onSuccess).ChgNm();
       }
       function onSuccess(value){
       document.getElementById('message').innerHTML= value;  
       }
    </script>
  <head>
    <base target="_top">
  </head>
  <body>
    <style>
.loader {
  border: 16px solid #f3f3f3;
  border-radius: 50%;
  border-top: 16px solid #3498db;
  width: 60px;
  height: 60px;
  -webkit-animation: spin 2s linear infinite; /* Safari */
  animation: spin 2s linear infinite;
}

/* Safari */
@-webkit-keyframes spin {
  0% { -webkit-transform: rotate(0deg); }
  100% { -webkit-transform: rotate(360deg); }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
</style>
    <div class ='loader' visibility : hidden>Working</div>
     <div id="message" style="color:green">test to unhide loader</div>    
    <p><button onclick="clickMe(); return false;">Look up my personal link</button></p> 
  </body>

代码

function doGet(e) {
  return HtmlService
    .createHtmlOutputFromFile('Index.html')
    .setTitle("Hello World Example");//We can set title from here
}

function ChgNm(){
  return "changed the name"
}
yhxst69z

yhxst69z1#

你犯了两个错误。

getElementsByClass()不是函数。请将其替换为getElementsByClassName(),如下所示:

document.getElementsByClassName('loader')[0].style.visibility = 'visible';

能见度:hidden是一个CSS属性,所以应该放在style属性里面,如下所示:

<div class ='loader'style="visibility:hidden">Working</div>

相关问题