为什么我的隐藏DIV根本不显示?

问题描述 投票:-2回答:2

我有一个必须重定向用户的表单(Salesforce的重定向要求的一部分)。我想将用户留在页面上,因此重定向链接是添加了“?submitted = 1”的同一页面。我已尝试在网上找到这么多不同的脚本来检查提交的URL,然后将div从none更改为block。它不起作用,我不知道为什么。这是我的最新代码,但请记住,我一直在搜索并尝试从这里和网络上的各种答案,所以我可能已经尝试了其他的东西。

这是我的HTML:

<div id="savingsSuccess">
    <div id="alertSuccess" class="alert alert-success">
      <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button><strong>Your inputs have been sent to our team, we will send your savings estimate to email</strong>
    </div>
</div>

我的CSS在这里:

#alertSuccess {
    display: none;
}

我的脚本如下:

<script type="text/javascript">
   if (/submitted/.test(window.location.href)) {
      document.getElementByID('alertSuccess').style.display = 'block';
   }
</script>

我究竟做错了什么?

javascript html css forms
2个回答
3
投票

你错误拼写方法getElementById,必须是Id而不是ID

Here是文档。


0
投票

我对你的脚本做了一些修改。

首先:我不是ID,只是为了让事情变得不那么强硬,我继续分裂/收集URL

HTML:

<div id="savingsSuccess">
    <div id="alertSuccess" class="alert alert-success">
      <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button><strong>Your inputs have been sent to our team, we will send your savings estimate to email</strong>
    </div>
</div>

CSS在这里:

#alertSuccess {
    display: none;
}

脚本

<script type="text/javascript">
   if (window.location.href.substring(window.location.href.lastIndexOf("?"),window.location.href.length-1).split("&").indexOf("submitted=1")==-1) {
      document.getElementById('alertSuccess').style.display = 'block';
   }
</script>
© www.soinside.com 2019 - 2024. All rights reserved.