我正在开发这个网站:http://parkoura.tk/a/sandbox/
我使用的是ajax导航。我有一个名为ajax()的函数,它应该在onload时执行。当它这样做的时候,我希望它首先检查是否有标签在那里。如果没有hashtag,那么函数就会中断,不会做任何事情。如果声明了一个hashtag,它会将ajax发送给另一个php,并替换div中的内容。
除了onload散列标签检查部分之外,它还可以很好地工作。当站点加载时,您可以看到一个滑块被渲染。尽管没有声明任何hashtag,但它仍然会继续替换内容。
我有警报来显示逻辑应该是如何工作的。我的实际检查逻辑是这样的:
<script>
if (typeof location.hash != 'undefined' || location.hash != '' || location.hash != '#' || location.hash != '#carousel')
{ no hash,things stay the same the function is not executed. 完整的js代码:https://pastee.org/v8cxp
发布于 2012-06-19 23:23:48
试试这个:
if(window.location.hash) {
// Process your ajax call
} else {
// "no hash,things stay the same the function is not executed. "
}可能的重复项:How can you check for a #hash in a URL using JavaScript?
https://stackoverflow.com/questions/11104040
复制相似问题