【问题标题】:How to alert hashtag after clicking an anchor单击锚点后如何提醒主题标签
【发布时间】:2019-02-16 11:59:43
【问题描述】:

我试图在单击产生# 标记的锚点时提醒# 标记。 但我只在页面刷新后收到警报:

锚点:

$folderanchor = "<a class='folderanchor' href='#".$dir.'/'.$file."'>$file</a>"; 
echo $folderanchor;

阅读#

$( document ).ready(function() {    
     if(window.location.hash) {
          var hash = window.location.hash.substring(1); //Puts hash in variable, and removes the # character
          alert (hash);
          // hash found
      } else {
          // No hash found
      }
}); 

单击锚点后应立即显示警报。我做错了什么?

【问题讨论】:

    标签: javascript php jquery url


    【解决方案1】:

    点击锚链接并不一定会重新加载页面。您可能希望为此使用事件。

    $('a[href^="#"]').click(yourFunction);
    

    这会在所有锚链接上设置点击事件。

    将您拥有的代码(没有文档准备部分)放入函数(yourFunction)中。

    【讨论】:

      【解决方案2】:

      加+

      href='# + ".$dir.'/'.$file."'

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-09-10
        • 2019-09-26
        • 1970-01-01
        • 2013-07-30
        • 1970-01-01
        相关资源
        最近更新 更多