Javascript 为什么不是';我的隐藏DIV根本没有显示出来吗?

Javascript 为什么不是';我的隐藏DIV根本没有显示出来吗?,javascript,html,css,forms,Javascript,Html,Css,Forms,我有一个表单必须重定向用户(Salesforce重定向需求的一部分)。我希望用户保持在页面上,因此重定向链接与添加了“?submitted=1”的页面相同。我已经尝试了许多不同的脚本,在网上找到检查提交的url,然后将div从none更改为block。它不起作用,我不知道为什么。这是我的最新代码,但请记住,我一直在搜索和尝试各种答案,从这里和周围的网络,所以我可能已经尝试了其他东西 这是我的HTML: <div id="savingsSuccess"> <div id=

我有一个表单必须重定向用户(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>
我的脚本如下:

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

if(/submitted/.test(window.location.href)){
document.getElementByID('alertSuccess').style.display='block';
}

我做错了什么?

您拼错了方法
getElementById
,必须是
Id
,而不是
Id


是文档。

我对您的脚本做了一些更改

首先:Id不是Id,只是为了让事情不那么骇人,我继续分割/子串URL

HTML:

剧本

<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>

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';
}

脚本标记是在div标记之前还是之后?如果在div存在之前运行JavaScript,那么使用href的正则表达式测试看起来不错。当脚本进入if语句时,您知道是否存在
#alertSuccess
?我会从这里开始。是的,脚本在div之后。但是,我使用的是
getElementByID
而不是
getElementByID
你说的“hackish”是什么意思?您看到的代码,我在这里找到的一个搜索结果中找到。如果文件路径包含单词“submitted”?这是一个小更改,但它是一个选项
<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>
#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>