如果 url 中带有#comment 或#map 的散列,我需要通过加载检测一次,以打开带有评论和 map 的损坏的 div。 这是我用来打开和关闭 div 的 JavaScript:
<script type="text/javascript">
function spoilinout(idinout){
if (document.getElementById) {
var dividinout = document.getElementById(idinout);
dividinout.style.display = (dividinout.style.display=='block'?'none':'block');
} }
</script>
我怎样才能检测到它? 谢谢 弗兰克
最佳答案
当前 URL 存储在 window.location.href
中,因此您可以随时测试:
if (window.location.href.match(/\#comment/))
{
// ...
}
关于javascript - 检查 #hash 标记的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6060149/