2016-02-13 34 views
-2

我在我的合同表单上有一个表单,它提交给第三方网站,然后我可以定义一个URL来返回用户。我现在将用户返回到同一个/联系页面,但我想给他们一个它已经提交的消息(因为ajax表单不适用于第三方),我不想整个页面。检测标签是否在URL中,然后删除隐藏的类

所以我有想法的用户返回到/联系#感谢

我有我的网站上一些代码,是这样的:

<div id="alert" class="hidden">Form Submitted. We will reply soon.</div> 

现在我想的JavaScript的一个小一点上我的页面检测URL是否有上面的#thanks标记,然后从我的alert div中删除隐藏的类。 JavaScript能够检测到这一点,如果是的话,我该怎么做呢?

+2

可能重复[如何检查URL中使用JavaScript #hash?](http://stackoverflow.com/questions/298503/ho w-can-check-for-a-hash-in-a-url-using-javascript) – JJJ

+0

检查位置api:https://developer.mozilla.org/en-US/docs/Web/API/位置 – jeff

回答

1

包括jQuery和脚本。我测试和工作

$(document).ready(function(){ 
    if(window.location.hash) { 
    $("#alert").show() 
    } 
}); 

SIII =是用散 Use hash

No hash

0

我不能完全肯定,我已经明白什么是你想实现的,但是这可能会帮助您:

if (window.location.hash === '#thanks') { 
    document.getElementById('alert').classList.remove('hidden'); 
}