Div 没有被隐藏

Div is not getting hidden

我正在推送一个 Google 跟踪代码管理器代码,其中包含以下脚本:

<script type="text/javascript">
  document.getElementByID('my-stealthy-popup')style.display = 'block';
</script>

这是针对当前设置为 div 的 id

<div id="my-stealthy-popup" style="width:500px;height:100px;border:1px solid #000;display:none;">This is a rectangle!</div>

它似乎没有对 div 做任何事情。我是不是做错了什么,或者你不能通过 GTM 像这样使用 JavaScript 吗?

实际上你有 2 个语法错误如下:

  1. 点。在

    中缺失

    document.getElementByID('my-stealthy-popup')style.display = 'block';

正确为

document.getElementByID('my-stealthy-popup').style.display = 'block';
  1. getElementByID改成getElementById

这是 运行 片段

 document.getElementById('my-stealthy-popup').style.display = 'block';
    <div id="my-stealthy-popup" style="width:500px;height:100px;border:1px solid #000;display:none;">This is a rectangle!</div>