【问题标题】:How to do autofocus for a google web app script?如何为谷歌网络应用程序脚本进行自动对焦?
【发布时间】:2021-11-07 12:26:02
【问题描述】:

我正在编写我的第一个 Google 网络应用程序。我正在尝试使用输入设置表单,但无法专注于第一个输入。在谷歌网络应用程序中进行自动对焦有什么技巧吗?在下面的代码中,焦点没有放在输入上。

<!DOCTYPE html> <html lang="en"> <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
     </head> <body>
    <form>
      <h1>Enter Loan Details</h1>
      <br>
      <label for="multiInput">Scan Number / Name or Hardware Tag</label>
      <input type="text" id="multiInput" name="multiInput"  autofocus>
    </form>   </body> </html>

【问题讨论】:

    标签: html google-apps-script


    【解决方案1】:

    专注于您选择的元素

    <!DOCTYPE html>
    <html>
      <head>
        <base target="_top">
      </head>
      <body>
         <h1>Hello</h1>
         <label>Your name: </label>
         <input id="first" type="text" size = "25" />
         <script>
           //waits for window to load
           window.onload = function() {
             document.getElementById('first').focus();
           }
         </script> 
      </body>
    </html>
    
    
        function showdialog() {
          let ui = SpreadsheetApp.getUi();
          ui.showModelessDialog(HtmlService.createHtmlOutputFromFile('ah2'),Test Dialog')
        }
    

    【讨论】:

    • 感谢帮助,脚本解决方案解决了问题,但我仍然想知道,为什么 google app 脚本破坏了输入的自动对焦属性。
    • 在 HtlmService 中有几件不同的事情。例如 HtmlService 不会读取 html 文件中的元标记。相反,您必须使用 addMetaTag() 方法来实现它们
    • 好的,我也不知道 - 感谢您的奖励提示。
    猜你喜欢
    • 2023-02-11
    • 1970-01-01
    • 2013-03-18
    • 2019-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-12
    • 1970-01-01
    相关资源
    最近更新 更多