Javascript hbs文件内脚本标记中的延迟属性

Javascript hbs文件内脚本标记中的延迟属性,javascript,html,express,express-handlebars,Javascript,Html,Express,Express Handlebars,我正在使用express用java脚本编写代码。我有一个index.hbs文件,它与html文件类似。我尝试在script标记中编写代码 <div class="container" style="display: flex; flex-direction:column; align-items: center; justify-content: center; font-family: 'Gill Sans', 'Gill Sans MT

我正在使用express用java脚本编写代码。我有一个index.hbs文件,它与html文件类似。我尝试在script标记中编写代码

<div class="container" style="display: flex; 
  flex-direction:column;
  align-items: center;
  justify-content: center; 
  font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;">
  <h1 style="color:pink">{{title}}</h1>
  <p style="color:tomato">Welcome to {{title}}</p>
  <div style="display: flex;
  align-items: center;
  justify-content: center">
    <form method="post" action="/urls">
      <label for="long">Enter the URL to Shorten</label>
      <br>
      <br>
      <input style="width: 400px" id="long" name="LongURL" placeholder="longUrl" />
      <input type="submit" value="Отправить">
    </form>
  </div>
  <h1 style="color:pink">Shortened URL's</h1>
  <ul>
    {{#each db}}
    <li style="width:100%">
      <p>{{this.longId}}</p>
      <a href="{{this.longId}}" target="_blank">
        <p>{{this.shortId}}</p>
      </a>
      <p>Number Visited: {{this.numberUsed}}</p>
    </li>
    {{/each}}
  </ul>
</div>

{{title}}
欢迎来到{{title}

输入要缩短的URL

缩短的URL
    {{{#每个db}}
  • 访问次数:{this.numberUsed}

  • {{/每个}}
查找带有标记a的元素。我会写字

<script>
  console.log(document.querySelector("a"));
</script>

console.log(document.querySelector(“a”));

在html文件的末尾,但是我想用defer来做。如果我在index.hbs内的html代码之前在脚本标记中写入此属性,它将返回空值。我该怎么做?

我需要把这个放在脚本的开始和结束标记中。我甚至不需要延迟,对吗?
// Try this way 
window.onload = function (){
    console.log(document.querySelector('a'))
}